Message Boards Message Boards

0
|
3868 Views
|
1 Reply
|
0 Total Likes
View groups...
Share
Share this post:

whats wrong with this code -> needs plotlegends? looking to display graph

Posted 10 years ago

can someone please help with the code? thx!

Needs["PlotLegends`"]
Interpretation[{f = "SPY", from = "Jan1,1980", to = "Dec31,2013", 
  n = 1, alpha = 0.88, beta = 0.88, lambda = 2.25, gamma1 = 0.61, 
  gamma2 = 0.69}, 
 Panel[Grid[{{Style["Cumulative Prospect Calculator", Bold], 
     SpanFromLeft}, {"Ticker:", InputField[Dynamic[f]]}, {"From:", 
     InputField[Dynamic[from]]}, {"To:", 
     InputField[Dynamic[to]]}, {"Rolling Days:", 
     InputField[Dynamic[n]]}, {"\[Alpha]:", 
     InputField[Dynamic[alpha]]}, {"\[Beta]:", 
     InputField[Dynamic[beta]]}, {"\[Lambda]:", 
     InputField[Dynamic[lambda]]}, {"\[Gamma]1:", 
     InputField[Dynamic[gamma1]]}, {"\[Gamma]2:", 
     InputField[Dynamic[gamma2]]}}]],
 data = FinancialData[f, {from, to, "Day"}];
 maxl = Min[Length[data[[All, 2]]] - 2, 500];
 cpt = ConstantArray[0, maxl];
 For[i = 1, i < maxl + 1, i++,
  return = data[[i + 1 ;;, 2]]/data[[;; -(i + 1), 2]] - 1;
  sortedreturn = Sort[return];
  positive = (Sign[sortedreturn] + 1)/2;
  negative = -(Sign[sortedreturn] - 1)/2;
  l = Length[return];
  b = Range[1, l];
  p = ((l + 1 - b)*positive + b*negative)/l;
  pstar = ((l - b)*positive + (b - 1)*negative)/l;
  gamma = gamma1*positive + gamma2*negative;
  wp = p^gamma/(p^gamma + (1 - p)^gamma)^(1/gamma);
  wpstar = pstar^gamma/(pstar^gamma + (1 - pstar)^gamma)^(1/gamma);
  pi = wp - wpstar;
  albe = alpha*positive + beta*negative;
  v = Abs[sortedreturn]^albe*(positive - lambda*negative);
  cpt[[i]] = Total[pi*v]];
 cptplot = Table[{Range[1, maxl][[i]], cpt[[i]]}, {i, 1, maxl}];
 Column[{Text@Row[{"CPT Value: ", cpt[[n]]}],
   Text@Row[{"CPT Value Graph: "}],
   ShowLegend[
    ListPlot[Tooltip[cptplot, "CPT"], Joined -> True, 
     PlotStyle -> Red, 
     ImageSize -> 
      400], {{{Graphics[{Red, Line[{{0, 0}, {1, 0}}]}], "CPT Value"}},
      LegendSize -> 0.8, LegendShadow -> None, 
     LegendPosition -> {1, 0}}]}]
 ]
Attachments:
POSTED BY: aa asd

The post http://community.wolfram.com/groups/-/m/t/270507 ,
How to post and use Wolfram Community
has suggestions for making chunks of WL code more legible.

POSTED BY: Bruce Miller
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract