Click here to Login





                                                   Set Global variable and running calculation Functions in MM script

  0

0
Kiran
2016-02-29 20:38:14


I'm tracking portfolio equity curve for different iterations of weight-allocations, and running into 2 issues -

1) I set a global Dictionary called equityGrid with weights Tuple as a key and equity curve TimeSeries as value - this is giving a compilation error - how do i declare this, so i can use it in OnBarPeriod?
SetVariable("equityGrid", new Dictionary<Tuple<int, int>, TimeSeries>());

2) I need to use 3 functions (ref, sharpe, stddev) in OnEndPeriod (to calculate return and sharpe ratio for this equity curve), but not sure how to code it so it gets parsed ..
ret = (curEquity[0] - ref(curEquity, lookback))/ref(curEquity, lookback));
sharp = sharpe(curEquity, lookback);
vol = stddev(curEquity, lookback);

If Data.ParseFormula( ) should be used, I don't know how to pass it the curEquity TimeSeries - Please advise code for this command.

thanks
Kiran



QuantShare
2016-03-01 02:45:28

  0

1/ Use KeyValuePair instead of tuple. They are the same. Tuple is not supported in the .Net Framework 2.0

2/ Unfortunately, this isn't possible. You cannot pass the "curEquity" series to the parser. You need to implement the standard deviation function from scratch then the Sharpe.

Example:
http://www.martijnkooij.nl/2013/04/csharp-math-mean-variance-and-standard-deviation/



Kiran
2016-03-01 16:27:04

  0

I'm using TimeSeries objects to store calculated values at each bar in my MM OnEndBar event.
I get a compilation error when i try to assign a value to the latest TimeSeries element - for example this assignment to curEquity[0] doesn't work
curEquity[0] = (i*close[0][0] + j*close[1][0] + (100-i-j)*close[2][0])/100.0;

How do i declare a time series vector in MM so i can assign values to each bar, plot it and use its past values in calculations - for example, also want to do this ..
perf = (curequity[0] - curequity[lookback])/curequity[lookback];



//// Sample code snippet
TimeSeries[] close;
close[0] = Data.GetPriceSeries(symbols[0], "close");
close[1] = Data.GetPriceSeries(symbols[1], "close");

Dictionary<string, TimeSeries> equityGrid = new Dictionary<string, TimeSeries>();
TimeSeries curEquity;
double maxsharp=-1000, maxret=-1000;

// Build equity curve for every allocation
for (int i=0; i<=100; i+=5) {
for (int j=i; j<=100; j+=5) {
string key = i.ToString() + "," + j.ToString();
curEquity = equityGrid[key];
curEquity[0] = (i*close[0][0] + j*close[1][0] + (100-i-j)*close[2][0])/100.0;
equityGrid[key] = curEquity;



Kiran
2016-03-01 21:01:17

  0

I tried to use Dictionary instead of TimeSeries, so i can store values in a List inside the Dictionary on each bar. Something like -
- Dictionary<string, List<double>> equityGrid = new Dictionary<string, List<double>>();

However, defining it locally in OnEndPeriod event doesn't seem to help as it doesn't retain the values in the list in the next OnEndPeriod bar. So, I tried Global definition as described in the document, but it gives a compilation error -
- SetVariable("equityGrid", new Dictionary<string, List<double>>());

1) Please advise how to define this Global dictionary, so i can store a value (equity value) at each bar in a List inside this dictionary.

2) Pl also address my earlier question reg how to store values in TimeSeries if possible - that would simplify the code dramatically, as i don't need to deal with Lists inside Dictionaries.



QuantShare
2016-03-02 08:43:31

  0

TimeSeries are readonly, you can use any other array or list to store values. Dictionary is good.

Do not declare the dic in OnEndPeriod but instead in the "Global" event if you want to use it in any other event.



Kiran
2016-03-02 10:16:03

  0

I tried declaring in Global event as described below, but it gives a compilation error -
- SetVariable("equityGrid", new Dictionary<string, List<double>>());

Please advise the declaration format that would work..
Do i need to also declare in the OnEndPeriod event?

thanks
Kiran



QuantShare
2016-03-02 10:29:59

  0

There is no SetVariable function. It should be: Global.SetVariable

Also, in the "Global" event (has nothing to do with the "Global" class), you should just declare the variable.

Example:
Dictionary<string, double[]> equityGrid = new Dictionary<string, double[]>();

You can now access "equityGrid" variable directly in other events.



No more messages
0




Reply:

No html code. URLs turn into links automatically.

Type in the trading objects you want to include: - Add Objects
To add a trading object in your message, type in the object name, select it and then click on "Add Objects"










QuantShare

Trading Items
Set Global Variable
Global Market Rotation Strategy V1.4
Auto Support and Resistance Indicator
Stock Ranking using Rate of Change and SMA Volume
Optimizable Fibonacci Long and Short Trading System

How-to Lessons
How to get stocks for a particular index using the global script
Difference between the watchlist and the screener tools
How to plot support and resistance lines automatically
How to create and trade a Neural Network model
How to execute a script at regular intervals

Related Forum Threads
Set Global Variable Between Strategy and AMM
AMM script global variables do not appear to be thread safe
Money Management Script variables and more
Best practices for using a Global Variable
Clear Symbol data stored in memory in global script

Blog Posts
QS Trading Software: Global Script
Charting & Scripts - Manage stock charts using the global script
Trading Indicators using the Rank and Percentile functions
New Ranking and Percentile Composite Functions
Running QuantShare on Amazon's EC2 Cloud & Automate Strategies Si...









QuantShare
Product
QuantShare
Features
Create an account
Affiliate Program
Support
Contact Us
Trading Forum
How-to Lessons
Manual
Company
About Us
Privacy
Terms of Use

Copyright © 2024 QuantShare.com
Social Media
Follow us on Facebook
Twitter Follow us on Twitter
Google+
Follow us on Google+
RSS Trading Items



Trading financial instruments, including foreign exchange on margin, carries a high level of risk and is not suitable for all investors. The high degree of leverage can work against you as well as for you. Before deciding to invest in financial instruments or foreign exchange you should carefully consider your investment objectives, level of experience, and risk appetite. The possibility exists that you could sustain a loss of some or all of your initial investment and therefore you should not invest money that you cannot afford to lose. You should be aware of all the risks associated with trading and seek advice from an independent financial advisor if you have any doubts.