Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Binary Tree For Stock Price
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
JDub10




PostPosted: Thu Oct 20, 2011 10:46 pm   Post subject: Binary Tree For Stock Price

Hello All,

First Post, wooot! So I took a computers class years ago in high school that touched on Turing. I was never great at it but still find programming interesting.

For my own interest I am trying to create a binary tree for a user defined stock price, volatility, and time-frame. A passion of mine is the financial markets and I want to create a program to save me time from manually writing out these trees. I'm sure there is something like this on the internet, and that is fine, but I want to create my own and understand how the code is working. About 1 hour in and I am stuck.

For example: Price is $100, volatility is 5%, what are the possible prices in 3 days.

Preferabbly I want the final outcome to look like this: http://bit.ly/rupxHx

I know the very minimal basics of Turing, i.e. establishing variables, put statments, get statements, loops. And also a bit rusty since highschool. As far as GUI or getting the outcome to look like the above I have no clue.

I'd post my code... but it is embarassing. My problem is how to store each outcome and then do a +/- of each, all the while outputting the results in an eye pleasing way.

Any help, advice is appreciated. Or any links to something similar where I can dissect others' code would be beneficial as well.

Thanks,
JDub
Sponsor
Sponsor
Sponsor
sponsor
Raknarg




PostPosted: Fri Oct 21, 2011 9:13 am   Post subject: RE:Binary Tree For Stock Price

I would help, but I don't really know much about economics...

However, I think something that would be helpful is looking into loops and recursion. I'm just guessing, but it seems like what you're looking for.

Also, if you want it to be put out in a pleasing way, you can look into drawing and such. Remember that there's a tutorial here for all basic concepts in Turing in the tutorial section.
Aange10




PostPosted: Fri Oct 21, 2011 10:11 am   Post subject: RE:Binary Tree For Stock Price

Also, as messy as your coding may be, it could be good to post it. As it may help us find out what level your at, and also help us to help you.

Turing Walkthrough -- This place has *most* basic concepts for turing in it.
Zren




PostPosted: Fri Oct 21, 2011 7:23 pm   Post subject: RE:Binary Tree For Stock Price

The variable names aren't correct. But half life is something like this.
future = base * (1 + r) ^ t

So you could find the min/max easily with this couldn't you?

100 * 0.95^3 .. 100 * 1.05^3

Recursion and exponents are usually linked.

~

Programmatically drawing this is much more complex than a simple formula however.

Recursion is necessary. A tutorial can be found in the walkthrough.

Storing the data is not necessary. While you can do it, it requires knowledge of custom data types (and some Object Oriented Programming). While you can do it in a single array (http://en.wikipedia.org/wiki/Binary_tree -> Methods for storing binary trees -> Array), learning to do it is probably way easier after you've sufficient OoP knowledge.

What's the reason I said storing the data isn't necessary? It is because your only reason for storing it is to immediately use it to draw afterwards. So instead, why not just draw as you recurse?

Your first task is to make a recursive method that will put "depth (time) and the current value". Don't worry about knowing it's history yet, we'll save that for formatting.

~

Before continuing with this post, think on how to put the data in a readable structure. Save your current work. Then save as a new file and test around with your ideas *cough simple version control basics cough*.

~

Your next task is to format this data.

Simple: Tab the put statements according to it's depth. Do to the nature of running a recursive function, the data will look like a neat tree.

Fancy: If you want it to look like the like the tree image you supplied, you'd have to start worrying about Cartesian coordinates (x,y). Start with finding where to draw the bubbles (Font.Draw + Draw.Oval), then worry about linking the lines.
JDub10




PostPosted: Sat Oct 22, 2011 8:05 pm   Post subject: RE:Binary Tree For Stock Price

Thanks for the replies! I'll check out those walkthroughs combined with what Zren said and post back with anymore questions... as I am sure I will have more
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 5 Posts ]
Jump to:   


Style:  
Search: