usim

Metronome and Vanguard Modules

Metronome

Metronome is the heart of usim, controlling how dataloaders and portfolio managers step through the time axis.

Usim provides futures metronome and stock metronome separately.


Vanguard

Just as explained in the workflow chapter, in realtime trading, metronome will block to wait for next ti along the time axis. Vanguard is imperative, since metronome needs vanguard to tell her whether the next tick arrives.

Thanks to usim's modulization feature, we could provide multiple vanguards for quant to choose from.


Vanguard Plain

Vanguard plain is the most plain vanguard provided by usim official version.

The design principle is to let vanguard constantly survey the latest quote' timestamp. As long as any contract's newest timestamp belongs to the next tick long the time axis, vanguard reports new tick arrives.

Define:

<module id="VGplain" type="vanguard" path="${libpath}/simulator/libvgplain.so" />

Config:

<vanguard module="VGplain" id="vg1"
instrument="IF" mercytime="100us" timeout="100ms"/>
  1. instrument : specifies the instruments vanguard plain needs to survey constantly. Usim will use security manager to get all related current trading constracts. For example, if instrument is IF, securitymanager will get all 4 IF contracts, copmare their last tradingday's volume, and choose the most liquid contract as her probe. She will constantly survey the timestamp of this probe later.

  2. mercytime: vanguard plain reports new tick arrives when any contract's newest timestamp belongs to next tick. But she can be configured to wait a mercytime after she find it and before she actually report it. This could be useful when you have multiple trading contracts, and their quotes are deem to arrive together. Hence you might want vanguard to wait a little time so that every contract gets its newest quotes;

  3. timeout: it is not uncommon for illiquid contracts to have no quotes for many ticks. Vanguard plain also have a local stopwatch to count how long she has been waited since last tick, if she finds she has waited for a interval+timeout interval and yet the newest quotes have not arrived, she just reports new ti arrives.


Vanguard Rabbit

Vanguard plain works fine when usim is trading with liquid contracts from one Exchange center, such as IF (index futures).

But there exists a serious drawback that she only querys one contract's timestamp to decide current time; Such policy generally fails when relevant contracts are listed and traded in different Exchanges, under which circumstances the timestamps of different Exchanges diverge and single contract's representitive fades.

Vanguard rabbit is more advanced and complex than vanguard plain, that she surveys a basket of contracts and use a simple policy to resolve their conflicts, then report the timestamp.

First, vanguard rabbit construct put all relevant contracts into different baskets according to their catelogue, for example, all 4 IF contracts go to IF basket, 4 IH contracts to IH basket;

Second, vanguard rabbit surveys each contract in every basket, marks the latest tick of the basket to her contracts' latest timestamp. For example, if in the 4 IF contracts, 3 are on tick of 100, 1 is on tick of 101, then the IF basket will be marked as on the tick of 101.

Third, vangaurd rabbit as a N parameter, acting as a threshold. If N baskets reach the next tick, then vanguard rabbit reports the next tick has arrived.

Define:

<module id="VGrabbit" type="vanguard" path="${libpath}/simulator/libvgrabbit.so" />

Config:

<vanguard module="VGrabbit" id="vg2"  N="2" timeout="100ms"/>
  1. N: the N parameter, explained above.

  2. timeout: the timeout configuration is exactly the same as that of vanguard plain.


Vanguard Localtime

Vanguard localtime is for backward compatibility purpose. She does not count on any outside quote timestamps, instead, she uses local time to decide if next ti arrives.

Define:

<module id="VGlocaltime" type="vanguard" path="${libpath}/simulator/libvglocaltime.so" />

Config:

<vanguard module="VGlocaltime" id="vg3"/>