Create a gist now

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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