How to create "synthetic" data based on existing data?
Author: fairone99
Creation Date: 7/3/2019 4:41 PM
profile picture

fairone99

#1
Hi!

I am interested knowing that is it possible using WLP to create "synthetic" data base on existing data?

To be exact, I want to create a reversed (short) version of NDX which is Nasdaq 100 index.

There are existing ETF for long version and short version of NDX and they are QQQ and PSQ, however their data are NOT back to the year of 1991 where NDX is.

If I can create a reversed version of NDX, it will provide me more data to run my strategy against and I think it will help tremendously.

Is it possible?

Also, the existing NDX has data back to the year of 1991 from Fidelity, is it possible to get data back even more year to the 80's?

Thanks,


Alex
profile picture

Eugene

#2
Hi,

If you share how one creates a reversed version of an instrument I'll tell you how it's possible.
profile picture

fairone99

#3
Hi! Eugene,

Sorry, I mean inverse not ""reverse".

Silly me... ; )


Alex
profile picture

Eugene

#4
Alex,

That's a good illustration of a clarification that doesn't make things more clear than they were. ;) I meant to ask how do you define an inverse version. What is the formula?
profile picture

fairone99

#5
Hi! Eugene,

As I only care about only daily data, so there are open and close for each bar.

At the same bar, the normal instrument price changes from open to close by 2% then the inverse instrument, at the same bar, price should change from open to close -2%. Same percentage change, but just become negative...

So, ((normal close) / (normal open) - 1) * 100 = Negative ((inverse close) / (invser open) - 1) * 100?


Alex

profile picture

Eugene

#6
Alex, the idea is to create a synthetic Bars object using Bars.SaveToFile and save it to your disk to be able to refer to it. Further reading:

1. QuickRef (F11 key in WLP) > SaveToFile

2. Wiki FAQ > Is it possible to create a DataSet from bars generated using SaveToFile (*.WL)?
profile picture

fairone99

#7
Eugene,

Many thanks!

I will give it a try and report the result back.



Alex
profile picture

Eugene

#8
You're welcome Alex. I don't think you should have much trouble coding your formula in WealthScript but feel free to drop me a note if any assistance is required.
profile picture

fairone99

#9
Hi! Eugene,

Good day!

I have given it a try and developed the following code to create inverse version of Yahoo's ^NDX which has the data from 1985 to today (Nasdaq 100 Index).

The code is here:

CODE:
Please log in to see this code.


It generates "almost" perfect inverse of ^NDX from 1985 to today.

However, if you check it out carefully, it is somewhat off a bit. The ^NDX from 1985 to today is range from 110 to 7800. So, I set my inverse ^NDX to start from 7800 so it should ends up to today to be very near 110, but it ends up to 11. I think it somewhat loses more and more accuracy as it progresses toward the end of this period. Thus, I try to improve accuracy by using all decimals for all the number calculation. However, the code at line 45, the bars.Add function is only taking in double that is why I need to cast all decimals to doubles (maybe lose accuracy here?).

As you can see the graph, it shows almost perfect inverse relationship. But, it is somewhat off a bit...

I really need your help as a second pair of eye to see if there is any logic coded wrong within my code. Also, how can I improve accuracy as the accuracy is getting worse and worse toward the end of the period?

Thank you for your help!


Alex
profile picture

Eugene

#10
Alex, I don't think that the "upconversion" of what inherently is double to a decimal makes sense. At first I considered operating with the split-unadjusted DataSeries like this but it doesn't help either:

CODE:
Please log in to see this code.

Sorry, I don't have any other ideas.
profile picture

fairone99

#11
Hi! Eugene,

No problem at all.

Just curious, the function at line 45, there is no other overloaded method for taking in decimals, right?

You are right about the decimals and doubles. Even if I take out all the decimals, and using all doubles, the restul is the same.

The code is getting complicated so I need some time to relax and rethink the possible solution in order to figure it out... ; )

Thanks.


Alex
profile picture

Eugene

#12
According to the WealthScript Programming Guide, a DataSeries is a series of floating point data values of type double. Consequently, each value in the series is double precision (14 to 15 significant digits). So no decimals, big integers or whatever - just double.
profile picture

fairone99

#13
Good to know that!

I have removed all the decimals from my code and the result is still the same...
profile picture

LenMoz

#14
CODE:
Please log in to see this code.
Hmmm Eugene, What does this line do? Is it documented?
profile picture

Eugene

#15
This website uses cookies to improve your experience. We'll assume you're ok with that, but you can opt-out if you wish (Read more).