I am working on a finance thesis. I want to create current month returns from daily stock prices. Futhermore, I need to get 3 month returns including current month. If the current month is Feb 2016, When I am looking at the 3 month returns, I am using returns from Feb, March, Apr of 2016. For example, Feb, Mar, Apr month returns were 10%, 20% and -10%. 3 months future return of Feb 2016 should be 1.1*1.2*0.9-1=1.188-1. Or, the beginning price of Feb is 100 and the ending price of Apr is 110. The 3 month future return of Feb is= (110-100) / 100 = 10%
I want to have1, 3, and 6 month future returns.
I have thousands of firms daily prices and I already calculated past month returns. I have added my code and my dataex below.
Permno is firm code, date is date, prc is price of stock, ret is daily returns.
Please let me know how I can code my idea. Thank you.
// CALCULATE MONTHLY DATE
gen int mdate = mofd(date)
format mdate %tm
foreach lag of numlist 1 3 6 {
sort permno mdate date
rangestat (first) prc (sd) volatility_`lag' = prc, by(permno) interval(mdate -`lag' -1)
by permno mdate (date): gen ret_`lag' = prc[1]/prc_first - 1
drop prc_first
}
----------------------- copy starting from the next line -----------------------
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input double permno long date double(shrcd exchcd prc ret) int mdate double volatility_1 float ret_1 double volatility_3 float ret_3 double volatility_6 float ret_6 10001 20457 11 2 7.519999980926514 .009395996108651161 672 . . . . . . 10001 20458 11 2 7.420000076293945 -.013297859579324722 672 . . . . . . 10001 20459 11 2 7.53000020980835 .014824816025793552 672 . . . . . . 10001 20460 11 2 7.639999866485596 .014608187600970268 672 . . . . . . 10001 20461 11 2 7.789999961853027 .019633520394563675 672 . . . . . . 10001 20464 11 2 8.0600004196167 .03465987741947174 672 . . . . . . 10001 20465 11 2 8.25 .023573147132992744 672 . . . . . . 10001 20466 11 2 8.25 0 672 . . . . . . 10001 20467 11 2 8.130000114440918 -.014545440673828125 672 . . . . . . 10001 20468 11 2 7.989999771118164 -.017220214009284973 672 . . . . . . 10001 20472 11 2 8.119999885559082 .0162703525274992 672 . . . . . . 10001 20473 11 2 8.079999923706055 -.004926103632897139 672 . . . . . . 10001 20474 11 2 8.100000381469727 .0024753042962402105 672 . . . . . . 10001 20475 11 2 8.220000267028809 .014814799651503563 672 . . . . . . 10001 20478 11 2 8 -.026764022186398506 672 . . . . . . 10001 20479 11 2 8.100000381469727 .01250004768371582 672 . . . . . . 10001 20480 11 2 8.199999809265137 .01234560739248991 672 . . . . . . 10001 20481 11 2 8.199999809265137 0 672 . . . . . . 10001 20482 11 2 8.319999694824219 .014634132385253906 672 . . . . . . 10001 20485 11 2 8.420000076293945 .01201927661895752 673 .27671314614485903 .11968087 .27671314614485903 .11968087 .27671314614485903 .11968087 10001 20486 11 2 8.489899635314941 .008301610127091408 673 .27671314614485903 .11968087 .27671314614485903 .11968087 .27671314614485903 .11968087 10001 20487 11 2 8.260000228881836 -.02707916684448719 673 .27671314614485903 .11968087 .27671314614485903 .11968087 .27671314614485903 .11968087 10001 20488 11 2 8 -.03147702291607857 673 .27671314614485903 .11968087 .27671314614485903 .11968087 .27671314614485903 .11968087 10001 20489 11 2 8.34000015258789 .04250001907348633 673 .27671314614485903 .11968087 .27671314614485903 .11968087 .27671314614485903 .11968087 10001 20492 11 2 8.630000114440918 .034772176295518875 673 .27671314614485903 .11968087 .27671314614485903 .11968087 .27671314614485903 .11968087 10001 20493 11 2 8.210000038146973 -.04866744577884674 673 .27671314614485903 .11968087 .27671314614485903 .11968087 .27671314614485903 .11968087 10001 20494 11 2 8.300000190734863 .010962259955704212 673 .27671314614485903 .11968087 .27671314614485903 .11968087 .27671314614485903 .11968087 10001 20495 11 2 8.050000190734863 -.030120480805635452 673 .27671314614485903 .11968087 .27671314614485903 .11968087 .27671314614485903 .11968087 10001 20496 11 2 8.300000190734863 .03105589933693409 673 .27671314614485903 .11968087 .27671314614485903 .11968087 .27671314614485903 .11968087 10001 20500 11 2 8.25 -.006024119444191456 673 .27671314614485903 .11968087 .27671314614485903 .11968087 .27671314614485903 .11968087 10001 20501 11 2 8.199999809265137 -.006060629151761532 673 .27671314614485903 .11968087 .27671314614485903 .11968087 .27671314614485903 .11968087 10001 20502 11 2 8.100000381469727 -.012195052579045296 673 .27671314614485903 .11968087 .27671314614485903 .11968087 .27671314614485903 .11968087 10001 20503 11 2 7.900000095367432 -.024691391736268997 673 .27671314614485903 .11968087 .27671314614485903 .11968087 .27671314614485903 .11968087 10001 20506 11 2 7.860000133514404 -.005063286051154137 673 .27671314614485903 .11968087 .27671314614485903 .11968087 .27671314614485903 .11968087 10001 20507 11 2 7.940000057220459 .01017810683697462 673 .27671314614485903 .11968087 .27671314614485903 .11968087 .27671314614485903 .11968087 10001 20508 11 2 7.880000114440918 -.007556668017059565 673 .27671314614485903 .11968087 .27671314614485903 .11968087 .27671314614485903 .11968087 10001 20509 11 2 7.940000057220459 .0076142060570418835 673 .27671314614485903 .11968087 .27671314614485903 .11968087 .27671314614485903 .11968087 10001 20510 11 2 7.840000152587891 -.012594446539878845 673 .27671314614485903 .11968087 .27671314614485903 .11968087 .27671314614485903 .11968087 10001 20513 11 2 7.860000133514404 .002551018027588725 673 .27671314614485903 .11968087 .27671314614485903 .11968087 .27671314614485903 .11968087 10001 20514 11 2 8.300000190734863 .0559796504676342 674 .2349002451136125 -.014251768 .2628324674888714 .10372343 .2628324674888714 .10372343 10001 20515 11 2 8.15999984741211 -.016867510974407196 674 .2349002451136125 -.014251768 .2628324674888714 .10372343 .2628324674888714 .10372343 10001 20516 11 2 8.199999809265137 .0049019563011825085 674 .2349002451136125 -.014251768 .2628324674888714 .10372343 .2628324674888714 .10372343 10001 20517 11 2 8.199999809265137 0 674 .2349002451136125 -.014251768 .2628324674888714 .10372343 .2628324674888714 .10372343 10001 20520 11 2 8.1899995803833 -.001219540135934949 674 .2349002451136125 -.014251768 .2628324674888714 .10372343 .2628324674888714 .10372343 10001 20521 11 2 8.079999923706055 -.013430972583591938 674 .2349002451136125 -.014251768 .2628324674888714 .10372343 .2628324674888714 .10372343 10001 20522 11 2 8.029999732971191 -.006188142579048872 674 .2349002451136125 -.014251768 .2628324674888714 .10372343 .2628324674888714 .10372343 10001 20523 11 2 8.119999885559082 .011207989417016506 674 .2349002451136125 -.014251768 .2628324674888714 .10372343 .2628324674888714 .10372343 10001 20524 11 2 8 -.014778311364352703 674 .2349002451136125 -.014251768 .2628324674888714 .10372343 .2628324674888714 .10372343 10001 20527 11 2 7.980000019073486 -.002499997615814209 674 .2349002451136125 -.014251768 .2628324674888714 .10372343 .2628324674888714 .10372343 10001 20528 11 2 7.900000095367432 -.010025053285062313 674 .2349002451136125 -.014251768 .2628324674888714 .10372343 .2628324674888714 .10372343 10001 20529 11 2 8.069999694824219 .02151893638074398 674 .2349002451136125 -.014251768 .2628324674888714 .10372343 .2628324674888714 .10372343 10001 20530 11 2 8.119999885559082 .0061958106234669685 674 .2349002451136125 -.014251768 .2628324674888714 .10372343 .2628324674888714 .10372343 10001 20531 11 2 8.199999809265137 .009852207265794277 674 .2349002451136125 -.014251768 .2628324674888714 .10372343 .2628324674888714 .10372343 10001 20534 11 2 8.199999809265137 0 674 .2349002451136125 -.014251768 .2628324674888714 .10372343 .2628324674888714 .10372343 10001 20535 11 2 8.199999809265137 0 674 .2349002451136125 -.014251768 .2628324674888714 .10372343 .2628324674888714 .10372343 10001 20536 11 2 8.239999771118164 .004878044128417969 674 .2349002451136125 -.014251768 .2628324674888714 .10372343 .2628324674888714 .10372343 10001 20537 11 2 8.079999923706055 -.019417457282543182 674 .2349002451136125 -.014251768 .2628324674888714 .10372343 .2628324674888714 .10372343 10001 20541 11 2 7.900000095367432 -.02227720618247986 674 .2349002451136125 -.014251768 .2628324674888714 .10372343 .2628324674888714 .10372343 10001 20542 11 2 7.889999866485596 -.0012658517807722092 674 .2349002451136125 -.014251768 .2628324674888714 .10372343 .2628324674888714 .10372343 10001 20543 11 2 7.889999866485596 0 674 .2349002451136125 -.014251768 .2628324674888714 .10372343 .2628324674888714 .10372343 10001 20544 11 2 7.809999942779541 -.010139407590031624 674 .2349002451136125 -.014251768 .2628324674888714 .10372343 .2628324674888714 .10372343 10001 20545 11 2 7.800000190734863 -.0012803779682144523 675 .13742525924620014 -.06024096 .22447660547009565 .03723407 .22447660547009565 .03723407 10001 20548 11 2 7.769999980926514 -.0038461806252598763 675 .13742525924620014 -.06024096 .22447660547009565 .03723407 .22447660547009565 .03723407 10001 20549 11 2 7.230000019073486 -.06949806213378906 675 .13742525924620014 -.06024096 .22447660547009565 .03723407 .22447660547009565 .03723407 10001 20550 11 2 7.079999923706055 -.020746901631355286 675 .13742525924620014 -.06024096 .22447660547009565 .03723407 .22447660547009565 .03723407 10001 20551 11 2 7.369999885559082 .04096044600009918 675 .13742525924620014 -.06024096 .22447660547009565 .03723407 .22447660547009565 .03723407 10001 20552 11 2 7.579999923706055 .02849389985203743 675 .13742525924620014 -.06024096 .22447660547009565 .03723407 .22447660547009565 .03723407 10001 20555 11 2 7.769999980926514 .025065971538424492 675 .13742525924620014 -.06024096 .22447660547009565 .03723407 .22447660547009565 .03723407 10001 20556 11 2 7.869999885559082 .012870000675320625 675 .13742525924620014 -.06024096 .22447660547009565 .03723407 .22447660547009565 .03723407 10001 20557 11 2 7.800000190734863 .0006353631615638733 675 .13742525924620014 -.06024096 .22447660547009565 .03723407 .22447660547009565 .03723407 10001 20558 11 2 7.599999904632568 -.0256410613656044 675 .13742525924620014 -.06024096 .22447660547009565 .03723407 .22447660547009565 .03723407 10001 20559 11 2 7.449999809265137 -.01973685435950756 675 .13742525924620014 -.06024096 .22447660547009565 .03723407 .22447660547009565 .03723407 10001 20562 11 2 7.21999979019165 -.030872486531734467 675 .13742525924620014 -.06024096 .22447660547009565 .03723407 .22447660547009565 .03723407 10001 20563 11 2 7.309999942779541 .012465395033359528 675 .13742525924620014 -.06024096 .22447660547009565 .03723407 .22447660547009565 .03723407 10001 20564 11 2 7.179999828338623 -.01778387278318405 675 .13742525924620014 -.06024096 .22447660547009565 .03723407 .22447660547009565 .03723407 10001 20565 11 2 7 -.025069614872336388 675 .13742525924620014 -.06024096 .22447660547009565 .03723407 .22447660547009565 .03723407 10001 20566 11 2 7.179999828338623 .025714261457324028 675 .13742525924620014 -.06024096 .22447660547009565 .03723407 .22447660547009565 .03723407 10001 20569 11 2 7.199999809265137 .002785512711852789 675 .13742525924620014 -.06024096 .22447660547009565 .03723407 .22447660547009565 .03723407 10001 20570 11 2 7.349999904632568 .020833346992731094 675 .13742525924620014 -.06024096 .22447660547009565 .03723407 .22447660547009565 .03723407 10001 20571 11 2 7.28000020980835 -.009523767977952957 675 .13742525924620014 -.06024096 .22447660547009565 .03723407 .22447660547009565 .03723407 10001 20572 11 2 7.329999923706055 .006868092343211174 675 .13742525924620014 -.06024096 .22447660547009565 .03723407 .22447660547009565 .03723407 10001 20573 11 2 7.300000190734863 -.004092732910066843 675 .13742525924620014 -.06024096 .22447660547009565 .03723407 .22447660547009565 .03723407 10001 20576 11 2 6.909999847412109 -.05342470481991768 676 .2633846021305704 -.1141026 .39412138769836946 -.17933494 .37214152515378085 -.08111704 10001 20577 11 2 7.039999961853027 .018813330680131912 676 .2633846021305704 -.1141026 .39412138769836946 -.17933494 .37214152515378085 -.08111704 10001 20578 11 2 7.039999961853027 0 676 .2633846021305704 -.1141026 .39412138769836946 -.17933494 .37214152515378085 -.08111704 10001 20579 11 2 7.014999866485596 -.0035511499736458063 676 .2633846021305704 -.1141026 .39412138769836946 -.17933494 .37214152515378085 -.08111704 10001 20580 11 2 6.880000114440918 -.019244441762566566 676 .2633846021305704 -.1141026 .39412138769836946 -.17933494 .37214152515378085 -.08111704 10001 20583 11 2 6.889999866485596 .0014534522779285908 676 .2633846021305704 -.1141026 .39412138769836946 -.17933494 .37214152515378085 -.08111704 10001 20584 11 2 6.96999979019165 .011611019261181355 676 .2633846021305704 -.1141026 .39412138769836946 -.17933494 .37214152515378085 -.08111704 10001 20585 11 2 7.050000190734863 .0114778196439147 676 .2633846021305704 -.1141026 .39412138769836946 -.17933494 .37214152515378085 -.08111704 10001 20586 11 2 7.099999904632568 .00709215784445405 676 .2633846021305704 -.1141026 .39412138769836946 -.17933494 .37214152515378085 -.08111704 10001 20587 11 2 7.150000095367432 .007042280398309231 676 .2633846021305704 -.1141026 .39412138769836946 -.17933494 .37214152515378085 -.08111704 10001 20590 11 2 7.119999885559082 -.004195833578705788 676 .2633846021305704 -.1141026 .39412138769836946 -.17933494 .37214152515378085 -.08111704 10001 20591 11 2 7.139999866485596 .0028089862316846848 676 .2633846021305704 -.1141026 .39412138769836946 -.17933494 .37214152515378085 -.08111704 10001 20592 11 2 7.059999942779541 -.011204470880329609 676 .2633846021305704 -.1141026 .39412138769836946 -.17933494 .37214152515378085 -.08111704 10001 20593 11 2 6.900000095367432 -.022662868723273277 676 .2633846021305704 -.1141026 .39412138769836946 -.17933494 .37214152515378085 -.08111704 10001 20594 11 2 6.880000114440918 -.0028985480312258005 676 .2633846021305704 -.1141026 .39412138769836946 -.17933494 .37214152515378085 -.08111704 10001 20597 11 2 6.900000095367432 .0029069739393889904 676 .2633846021305704 -.1141026 .39412138769836946 -.17933494 .37214152515378085 -.08111704 10001 20598 11 2 6.900000095367432 0 676 .2633846021305704 -.1141026 .39412138769836946 -.17933494 .37214152515378085 -.08111704 10001 20599 11 2 6.949999809265137 .007246335037052631 676 .2633846021305704 -.1141026 .39412138769836946 -.17933494 .37214152515378085 -.08111704 end format %d date format %tm mdate
Listed 100 out of 5502429 observations
Use the count() option to list more
0 Response to Getting the current and future 1, 3, 6 month returns
Post a Comment