position tracker resets when the strategy is relaunched ?

24 views
Skip to first unread message

mdjam...@gmail.com

unread,
Oct 31, 2014, 2:07:16 PM10/31/14
to tbg-quant...@googlegroups.com
dear all,

How to keep in opened of positiontracker when the strategy is reseted ?

is it possible to fill it with data stored in the h2db database ?

best regards.

Alberto Sfolcini

unread,
Nov 1, 2014, 4:36:01 AM11/1/14
to tbg-Quant-community
Hi James,

Well, first you need to run with a persistence support, default runs with in-memory h2db.

At this time there is no support for this feature which is quite easy to implement.
We did a custom implementation for OpenHedgeFund (openhedgefund.com) that does exactly the same stuff, we cannot merge it into tbg-quant repo because that customization includes a lot of other work which is not supposed to be shared.

OpenHedgeFund customization includes mysql/mariadb support and trading system refill with positiontracker, and all other stuff, data included. This way you can stop&run your trading system all the time you want.

About tbg-quant, we do not have a plan for this feature but we can support you or any other volunteers to write it.
Feel free to contact me if you need further details.

thank you


--
www.thebonnotgang.com
---
You received this message because you are subscribed to the Google Groups "tbg-Quant-community" group.
To post to this group, send email to tbg-quant...@googlegroups.com.



--
Alberto Sfolcini

mdjam...@gmail.com

unread,
Nov 1, 2014, 12:50:17 PM11/1/14
to tbg-quant...@googlegroups.com
Thanks Alberto.

I will implement this feature for my need. Could you please provide some documentatiom to achieve this goal without to much pain ?

Best regards

Alberto Sfolcini

unread,
Nov 1, 2014, 1:03:02 PM11/1/14
to tbg-Quant-community
James, I will provide you all the help you need as soon as I will have some free time.

First, start to get confident with a persistent h2, you can change the settings in your tbg-quant.properties file.
I will let you know more about this.

bye

--
www.thebonnotgang.com
---
You received this message because you are subscribed to the Google Groups "tbg-Quant-community" group.
To post to this group, send email to tbg-quant...@googlegroups.com.



--
Alberto Sfolcini

mdjam...@gmail.com

unread,
Nov 1, 2014, 2:08:52 PM11/1/14
to tbg-quant...@googlegroups.com
I already changed config to have persistence and started navigating through tables to understand the organisation of stored data.

I need to go one step further and understand the organisation of positiontracker in order to fill it with data from h2.

Thanks for your help and openmind.

Best regards.

Alberto Sfolcini

unread,
Nov 1, 2014, 3:24:32 PM11/1/14
to tbg-Quant-community
Hi,

I just gave a very quick look at the code I wrote for OpenHedgeFund and these are the basic suggestion I can give you at the moment:

You are not forced to run tbg-quant with persistence to obtain what you want.

If you want to running it with inmemory option ( faster and suggested for high frequency strategies ) you should store your portfolio object at the stop of the trading system. This means that when the trading system is stopping, before exit, it save the portfolio object somewheere (can be even a CSV file).

/**
* on TradingSystem stops...
*/
public void onStop(){
log.info("onStop(): ");
ArrayList<Position> closedPositions = storeService.getHistoricalPositions();
closedPositions.addAll(historicalPosition);
ArrayList<Position>   openPositions = portfolio;

savemyStatus(closedPositions,openPositions);
}

Let's do something simple but maybe one of the best solution, let's say you want to use inMemory setting and use a CSV file to save your TradingSystemStatus. Just create this method savemyStatus(closedPositions,openPositions); 
and save closed and openPosition inside a CSV formatted as you prefer.

So if you do this you just done half of the work. 

Let's say that you save these info in a CSV file, now when the system starts you have to load these data and fills the our objects.
Create a Position p = new Position(), fill it with the csv data! 

so... onStarts(){

     // load CSV data
     for every line{
         Position p = new Position();
         fill p
         you shoudl be able to get the status of the position ( OPEN or CLOSED ) because it will fill different objects

/* Fill the Portfolio Object */
if (status.equalsIgnoreCase("OPEN")){
portfolio.add(p);
positionTracker.setPortfolio(portfolio);
this.account.updatePortfolio(s.getSymbol().toString(), p); // update the account portfolio!!
// the last event is not filled-up, but this is not an issue! an exception will be raised.
}
/* Fill the Historical Position Object */
if (status.equalsIgnoreCase("CLOSED")){
historicalPosition.add(p);
}
     }
}


Hope this helps, maybe I missed something, I cant be sure I just looked at the code but did not try anything.

let me know if you need more details.
thank you  bye
alberto



--
www.thebonnotgang.com
---
You received this message because you are subscribed to the Google Groups "tbg-Quant-community" group.
To post to this group, send email to tbg-quant...@googlegroups.com.



--
Alberto Sfolcini

mdjam...@gmail.com

unread,
Nov 1, 2014, 3:44:34 PM11/1/14
to tbg-quant...@googlegroups.com
Thanks for the trick, I will start by using this approach. If ok i will translate it to h2. Speed is more important at the onevent stage than at start and stop stages. Furthermore, Having thèse information in h2 would give à more reliable audit trial.

I have one question: do i have also to save and restore the account status/data ?
Best regards.

Sfl

unread,
Nov 4, 2014, 4:38:18 AM11/4/14
to tbg-quant...@googlegroups.com, mdjam...@gmail.com
Hi,

InMemory vs. persistence matter not only in start/stop moment but also in execution because everything is being logged (executions, etc.. ).
Thus, inmemory it's a better option if you really do high frequency tranding. If you trade the minute persistence it's fine too.
Do you have to save your account status ? it maybe usefull for statistical reasons.
You can also decide to have your personal persistence layer with the architecture you prefer.

bye
Reply all
Reply to author
Forward
0 new messages