Click here to Login





                                                   using GetCustomDatabaseData on Earnings calendar database

Back to threads - Tags: --
  0

0
Borbely Zsolt
2020-05-21 08:59:57


Hi,

I am trying to implement a rule in my Trading System, where I would like to close the position on a symbol before 3 days of the earning and reopen 5 days after the earning if some certain conditions are met.
I am backtesting using the Historical Earnings Calendar for Major Stock Exchanges: https://www.quantshare.com/item-742-historical-earnings-calendar-for-major-stock-exchanges
I was trying to use GetCustomDatabaseData in the Money Management script in the following way:

Example:
string symbol = "TSLA";
VectorCustom earnings_cal_Timeday = Data.GetCustomDatabaseData("earnings_cal", "timeday", symbol);
for(int earningsTimedayIndex = 0; earningsTimedayIndex < earnings_cal_Timeday.Count; earningsTimedayIndex ++)
{
CustomDatabaseValues customValues = earnings_cal_Timeday.GetValue(earningsTimedayIndex);
for(int earningsTimedayValueIndex = 0; earningsTimedayValueIndex < customValues.Length; earningsTimedayValueIndex ++)
{
var timedayValue = customValues.GetValue(earningsTimedayValueIndex);
if(timedayValue != null)
{
string timeday = timedayValue.ToString();
}
}
}

It looks like the customValues.Length is always 0. What I am doing wrong?

Unfortunately I did not found an useful example which would demonstrate the usage of the GetCustomDatabaseData.

Could you please provide me an example how could I check whether there is or not and earning announcement in the next 3 days or if there was one 5 days ago based on the Divers.CurrentDate.
What would be the best solution for this problem?

Thanks,
Zsolt



QuantShare
2020-05-21 15:23:46

  0

Hi Zsolt,

You can use the QS language instead of the money management tool.

e1 = GetDataCount("earnings_cal", "timeday");
buy = hhv(e1, 5) > 0; // earnings in the past 5 bars
buy = hhv(e1, -3) > 0; // earnings in the next 3 bars

You can plot these on a chart to have a visual confirmation.



Borbely Zsolt
2020-05-21 17:58:53

  0

Thank you for your quick response.

My Trading system needs some advanced calculation which are not supported in the QS language (some calculations are using the EntryPrice which as I understood is not available in the QS language), therefore most of my strategy is implemented inside the Money management tool.
Isn't possible to achieve the same result in the Money management tool what you have provided in QS language?
Any other alternatives?

Thanks,
Zsolt



QuantShare
2020-05-22 00:41:37

  0

The "VectorCustom" class will contains database data. To access the current bar date, you need to use [0], to get the previous bar [1].

Example:
VectorCustom earnings_cal_Timeday = Data.GetCustomDatabaseData("earnings_cal", "timeday", symbol);
CustomDatabaseValues c = earnings_cal_Timeday[0]; // To get current bar data

The easiest way to achieve what you want is to mix C# with QS language. Example:
TimeSeries t = Data.ParseFormula("a = rsi(14);").GetTimeSeries(symbol, "a");

t[0] to get current bar RSI value (in the above example)



Borbely Zsolt
2020-05-22 08:40:45

  0

Thank you for your answer.

Yes I am using the mixture of C# code with QS language and it works well.

Regarding to the custom database read, as I understood I can use earnings_cal_Timeday[0]; to get the current bar data and earnings_cal_Timeday[1]; to get the previous bar data, but as I see it isn't possible to get the next bar data, because the earnings_cal_Timeday VectorCustom contains data until the current bar. Is this true?

In my case I need to get data for the next days as well. Is this possible?

Thanks,
Zsolt



QuantShare
2020-05-24 13:03:43

  0

Yes correct. To get next bar data, you need to get data from QS language using the "Data.ParseFormula" function.


Borbely Zsolt
2020-05-24 18:05:58

  0

Hi,

Unfortunately based on your answers it is still not clear how can I get the data what I need using the money management script combining with "Data.ParseFormula" function.

So let summarize here what I want to achieve:
I am using the following database for the earnings calendar:
(see the screenshot)
https://drive.google.com/open?id=12XxZL67Jmd3HNRCq6AhWHONJSGsaJKsN

What I need is very simple, in the money management script I want to check if there will be an earning announcement 3 bars later or not.
Knowing the database I am using could you please provide me the exact code using Money Management script ( and combined with QS language if it is needed) to achieve what I need.

Thanks,
Zsolt



QuantShare
2020-05-25 13:13:43

  0

Best Answer
Here is the formula:
string str = "e1 = GetDataCount('earnings_cal', 'timeday');a = hhv(e1, -3) > 0;";
TimeSeries t = Data.ParseFormula(str).GetTimeSeries(symbol, "a");
if(t[0] > 0)...



Borbely Zsolt
2020-05-25 18:02:24

  0

Thank you for your answer, below is the code which is finally working as I expected:

string str = "e1 = GetDataCount('earnings_cal', 'timeday');a = hhv(ref(e1, -3),1) > 0;";
TimeSeries t = Data.ParseFormula(str).GetTimeSeries(symbol, "a");

I had to replace the hhv(e1, -3) > 0; with hhv(ref(e1, -3),1) > 0; because I have to move 3 bars ahead and for that bar I am checking whether there is an announcement or not.

Thank you for your help!




QuantShare
2020-05-26 14:45:47

  0

Thank you. Yes, you are right, "hhv" doesn't look forward, so you needed to move the "e1" series forward first.


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
Historical Earnings Calendar Data for U.S. Stocks - Date/Time and...
Historical Earnings Calendar for Major Stock Exchanges
Earnings database
Earnings Surprise Strategy
Economic Calendar

How-to Lessons
How to download earnings calendar data for various stocks
How to download and use U.S. stocks earnings data
How to quickly select stocks based on the last value of a databas...
How to display Forex economic calendar data in a chart
How to plot a stock using different periods in the same chart

Related Forum Threads
Historical Earnings Calendar doesn't download after Nov 2016
Can I update the sector and industry information in the stock dat...
Problems Downloading Historical Earnings Data
Export to CSV the whole database including symbols
Backtest/Optimizing speed vs Size of Database & Vector vs loo...

Blog Posts
How to create a trading system, screen and composite using earnin...
Trading Items: Data Download using .Net Scripts
Speed Up Optimizations by Saving Ranking Data into a Custom Datab...
Charting, Backtesting and Trading using Fundamental Data
Download quotes, news, sentiment, fundamental... data using Quant...









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 2020 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.