Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

From |
Rohit Sonika <net@rsonika.me> |

To |
statalist@hsphsun2.harvard.edu |

Subject |
Re: st: Solving simultaneous equations |

Date |
Fri, 3 May 2013 19:31:51 +0100 |

Thanks for your response. It seems to be working for me now, although I am not sure how I can simulate this like 10000 times, each time saving some variables like price, strike, val, vol, etc. Thanks! Rohit On 3 May 2013, at 18:54, Aljar Meesters <aljar.meesters@gmail.com> wrote: > Dear Rohit, > > Your program works for me after some minor adjustments but I am using > Stata 12.1 so you may need to update (see -help update-). > The adjustments that I need to make are replacing set obs 10000 with > set obs 2 and add scalar n = 1. > You have two equations that you want to solve and thus you only need > two observations, one for each equation. The scalar n = 1 is needed > since you multiply by n by generating your a variable. > Best, > > Aljar > > Best, > > Aljar > > > > 2013/5/3 Rohit Sonika <net@rsonika.me>: >> Hi, >> >> I have never programmed in Stata, so I am reaching out to the community for some help. Here is my problem: >> >> I have two equations, with two unknowns as follows: >> >> 1. price = val - (a/b)*(val*normal(price/strike) - strike*normal(price/strike)) >> 2. sd = vol * (val/price) * (1-(a/b)*strike*normal(price/strike)) >> >> The two unknowns in the above equations are 'val' and 'vol' while the other variables are observed. >> >> I am taking a numerical approach to trying to solve for above equations. Since, I create a dataset and declare variables as follows: >> >> set obs 10000 >> gen double price = (100-1)*runiform()+1 >> gen double strike = (100-1)*runiform()+1 >> gen rate = 0.0025*int(60*runiform()) >> gen double b = 100 >> gen double a = (0.15-0.0001)*runiform()*n >> gen double sd = (0.30-0.05)*runiform()+0.05 >> >> The program I created to populate values of 'val' and 'vol' is as follows: >> >> program nlwar >> syntax varlist(min=1 max=1) [if], at(name) >> >> tempname val vol >> scalar `val' = `at'[1,1] >> scalar `vol' = `at'[1,2] >> >> tempvar abc >> gen double `abc' = `val' - (a/b)*(`val'*normal(`val'/strike * `vol') - strike*normal(`val'/strike)) - price + 1 in 1 >> replace `abc' = (`vol'/sd) * (`val'/price) * (1-(a/b)*strike*normal(`val'/strike)) - 1 in 2 >> >> replace `varlist' = `abc' >> end >> >> gen y = 0 >> replace y = 1 in 1 >> nl war @ y, parameters(val vol) initial(val 1 vol 1) >> >> When I run the above program, Stata gives me an error stating 'verify that nlwar is a function evaluator program'. >> >> Any help on this query would be appreciated. I am using Stata version 12. >> >> Thanks! >> Rohit >> * >> * For searches and help try: >> * http://www.stata.com/help.cgi?search >> * http://www.stata.com/support/faqs/resources/statalist-faq/ >> * http://www.ats.ucla.edu/stat/stata/ > * > * For searches and help try: > * http://www.stata.com/help.cgi?search > * http://www.stata.com/support/faqs/resources/statalist-faq/ > * http://www.ats.ucla.edu/stat/stata/ * * For searches and help try: * http://www.stata.com/help.cgi?search * http://www.stata.com/support/faqs/resources/statalist-faq/ * http://www.ats.ucla.edu/stat/stata/

**References**:**st: Solving simultaneous equations***From:*Rohit Sonika <net@rsonika.me>

**Re: st: Solving simultaneous equations***From:*Aljar Meesters <aljar.meesters@gmail.com>

- Prev by Date:
**Re: st: Solving simultaneous equations** - Next by Date:
**RE: st: gradient and the inverse of the information matrix** - Previous by thread:
**Re: st: Solving simultaneous equations** - Next by thread:
**Re: st: Non-linear model + More parameters than variables + -ml-** - Index(es):