Serving the Quantitative Finance Community

 
User avatar
TimG
Topic Author
Posts: 3
Joined: March 5th, 2008, 6:57 pm

Newbie C++ question.

December 4th, 2010, 5:26 pm

I'm looking to create code that calculates a table of (possibly) recursive functions. Basically like a spreadsheet where each columns is a function that can depend on other columns and/or preceding rows /succeeding rows of the same column.I'm guessing I need to set this up so that the return value of each function is cached for each row and that "cells" are calculated in an order that minimises the depth of recursion.Is this a good way of achieving this? Is this an obvious problem with an obvious solution?Are there any libraries out there that facilitate this?I'm looking at learning C++ via a project that at it's heart are these types of calculations. As a newbie to both C++ and OOP it would be helpful to know what a good starting point would be. Ideally I want an open source implementation of the above that I can take apart and tailor to my needs.Cheers,Tim.
 
User avatar
Cuchulainn
Posts: 65000
Joined: July 16th, 2004, 7:38 am
Location: Ganymede

Newbie C++ question.

December 4th, 2010, 5:37 pm

Jumping into recursive spreadsheet functions is not a good way to learn C++. The actual solution uses a Propagator design pattern... It is a bridge too far at this moment.I would advise Bruce Eckel's "Thinking in C++"; I think it is even free downloadable from his site. Study it and do the examples. Then take it from there. I reckon 1-2 years. And not too much 'pure' OOP, but also modular and template programming. As you progress you can start developing your own classes and insights. The problems with open source can be 1) little doc 2) it is based on one person's view of software 3) too big for newbies.
Last edited by Cuchulainn on December 3rd, 2010, 11:00 pm, edited 1 time in total.
65000
 
User avatar
TimG
Topic Author
Posts: 3
Joined: March 5th, 2008, 6:57 pm

Newbie C++ question.

December 4th, 2010, 5:54 pm

Thanks for the speedy reply.I already have the book in hard copy and am working my way through it. The excercises are good and I like the way that the code so far focusses on what is the initial barrier: basic pointers and basic memory management. Other books I've flicked through seem to place a lot of emphasis on making cat inherit animal, as though this would help you on the most important aspect: getting you get started in solving your own problems.I'll have a look at the propogater design pattern and see if it is a bridge too far! Otherwise I'll have to stick to the excercises.Also, can you recommend any good books that focus not on syntax etc, but on the sort of stuff you'd learn through working with experienced programmers? I.e good design/ habbits etc?
 
User avatar
TimG
Topic Author
Posts: 3
Joined: March 5th, 2008, 6:57 pm

Newbie C++ question.

December 4th, 2010, 7:56 pm

I've had a look at observer (I can't find much on propogator) and although i don't claim to understand it fully, I think it's a step beyond what I'm after.In my application almost all "cells" will require change if any change occurs, so I guess I don't need to have an efficient/guaranteed way of updating dependents. What I'm after is a mechanism to implement spreadsheet like beaviour while avoiding stack overflows/ being as effiicient as possible..If I'm talking rubbish please forgive me!Thanks,Tim.
 
User avatar
tagoma
Posts: 18849
Joined: February 21st, 2010, 12:58 pm

Newbie C++ question.

December 4th, 2010, 8:06 pm

thinking of the propagator dp. ???http://diegworld.blogspot.com/2010/10/p ... ttern.html it is based on a post dealing with a C# code fort the propagator dp. :http://www.codeproject.com/KB/architect ... gator.aspx
Last edited by tagoma on December 3rd, 2010, 11:00 pm, edited 1 time in total.
 
User avatar
spv205
Posts: 478
Joined: July 14th, 2002, 3:00 am

Newbie C++ question.

December 4th, 2010, 8:35 pm

TimG As Cuch said, the propagator pattern is what you are after. Its just that abstract descriptions are not very useful for a beginner to learn.So you create a class to represent a cell. this class has a container to store the cells it provides data to.you provide an update function for the class. this updates the cells value and calls update on all the cells in the container for that cell.
 
User avatar
Cuchulainn
Posts: 65000
Joined: July 16th, 2004, 7:38 am
Location: Ganymede

Newbie C++ question.

December 5th, 2010, 1:39 pm

QuoteOriginally posted by: spv205TimG As Cuch said, the propagator pattern is what you are after. Its just that abstract descriptions are not very useful for a beginner to learn.So you create a class to represent a cell. this class has a container to store the cells it provides data to.you provide an update function for the class. this updates the cells value and calls update on all the cells in the container for that cell.Here is the original articlehttp://wwwipd.ira.uka.de/~tichy/publications/propagator.docNote thate each node also has a reference to its parent and methods are thread-safe. BTW the implementation using Signals will be Vol II of our boost book. We already discuss (much-needed) redesign of Observer in Vol I. One _very_ important consequence in Signals is that observers need not be defined in the same class hierarchy. All they need is operator ()
Last edited by Cuchulainn on December 4th, 2010, 11:00 pm, edited 1 time in total.
65000
 
User avatar
Cuchulainn
Posts: 65000
Joined: July 16th, 2004, 7:38 am
Location: Ganymede

Newbie C++ question.

December 5th, 2010, 1:42 pm

QuoteOriginally posted by: TimGI've had a look at observer (I can't find much on propogator) and although i don't claim to understand it fully, I think it's a step beyond what I'm after.In my application almost all "cells" will require change if any change occurs, so I guess I don't need to have an efficient/guaranteed way of updating dependents. What I'm after is a mechanism to implement spreadsheet like beaviour while avoiding stack overflows/ being as effiicient as possible..If I'm talking rubbish please forgive me!Thanks,Tim.It's very laudable to take this example, but you should check for lacunae in C++. For example, you you know most of the stuff here It is a baseline.
Last edited by Cuchulainn on December 4th, 2010, 11:00 pm, edited 1 time in total.
65000