Skip to content

Instantly share code, notes, and snippets.

@blippy
Created March 16, 2018 12:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save blippy/0ebbdeab2a020311aa996f7817b5c7eb to your computer and use it in GitHub Desktop.
Save blippy/0ebbdeab2a020311aa996f7817b5c7eb to your computer and use it in GitHub Desktop.
Portfolio in Mathematica
#!/usr/bin/env wolframscript
(* ::Package:: *)
(* ::Input:: *)
(*tbl1 = Import[FileNameJoin[{$HomeDirectory , "tmp", "port.tsv"}]];*)
(* ::Input:: *)
(*(* Some of the types of prices you can ask for *)*)
(**)
(*(* First, some helper functions *)*)
(*Fina[sym_, what_] := EntityValue[Entity["Financial", sym], what];*)
(*Fina2[sym_, what_] := Part[Fina[sym, what], 2];*)
(**)
(*(* And now the real deal ... *)*)
(*OpenPrice[sym_] := Fina[sym, "Open"];*)
(**)
(*(* These can seem a little unreliable: *)*)
(*ClosePrice[sym_] := Fina[sym, "Close"];*)
(*AskPrice[sym_] := Fina2[sym, "Ask", 2];*)
(*LastPrice[sym_] := Fina2[sym, "Last"];*)
(* ::Input:: *)
(**)
(*f[row_] := (r1 =row[[1]]; r2 = row[[2]]; sp = OpenPrice[r1]; {r1,r2, sp, r2*sp});*)
(*tover[fn_] := Table[fn[tbl1[[r]]], {r, Length[tbl1]}];*)
(*tbl2 = tover[f];*)
(*tbl3 = Grid[tbl2, Alignment -> Right]*)
(**)
(* ::Input:: *)
(*port = Total[tbl2[[All, 4]]] *)
(*Print[port]*)
(* ::Input:: *)
(*Now*)
(* ::Input:: *)
(*EntityProperties["Financial"]*)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment