opt-pos-chart-tmpl.html 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <html>
  2. <head>
  3. <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
  4. <script type="text/javascript" src="https://www.google.com/jsapi"></script>
  5. <script type="text/javascript">
  6. google.load("visualization", "1.1", {packages:["bar"]});
  7. google.load('visualization', '1', {'packages':['table']});
  8. // google.load("visualization", "1.1", {packages:["corechart"]});
  9. google.setOnLoadCallback(drawChart);
  10. function drawChart() {
  11. var data = google.visualization.arrayToDataTable([
  12. ['Strike Price', 'P', 'C', ],
  13. {{{dataPCpos}}}
  14. ]);
  15. var dataTbl = google.visualization.arrayToDataTable([
  16. {{{dataTablePos}}}
  17. ]);
  18. var options = {
  19. width: 900,
  20. chart: {
  21. title: 'Option Postion Distribution. PUT:CALL Ratio [{{{PRvsCR}}}}]',
  22. subtitle: 'for the month of {{{option_months}}}',
  23. },
  24. };
  25. var chart = new google.charts.Bar(document.getElementById('barchart_material'));
  26. chart.draw(data, options);
  27. // chart table display implied volatilities in a nicely formatted table
  28. var chartTbl = new google.visualization.Table(document.getElementById('chartTbl_div'));
  29. var portTbl = new google.visualization.Table(document.getElementById('portTblDiv'));
  30. var formatter = new google.visualization.NumberFormat({pattern:'0.00'});
  31. for (var i = 2; i < 9; i++)
  32. formatter.format(dataTbl, i);
  33. var options2 = {
  34. displayAnnotations: true,
  35. showRowNumber: true, width: '100%', height: '100%', allowHtml: true,
  36. };
  37. chartTbl.draw(dataTbl, options2);
  38. $('input[id="b_reload"]').click();
  39. }
  40. // $(document).ready(function () {
  41. $('input[id="b_reload"]').click(function () {
  42. // var formatter = new google.visualization.NumberFormat({pattern:'0.00'});
  43. // for (var i = 0; i < 9; i++)
  44. // formatter.format(portTbl, i);
  45. var options3 = {
  46. displayAnnotations: true,
  47. showRowNumber: true, width: '100%', height: '100%', allowHtml: true,
  48. };
  49. $.ajax({
  50. type: 'Post',
  51. url: '/ws_position_summary',
  52. success: function (data) {
  53. alert(data);
  54. var jdata = JSON.parse('{"rows": [{"v": 0.047488620928674306}, {"v": -34.1918070686455}, {"v": 35.01931221132403}, {"v": -69.21111927996955}, {"v": 0.0}, {"v": 4350.744926215475}, {"v": -297.6744472363985}, {"v": 4648.419373451876}, {"v": 89903.71832036527}, {"v": "20150915231057"}, {"v": "OK"}], "cols": [{"type": "number", "label": "delta_1percent"}, {"type": "number", "label": "delta_all"}, {"type": "number", "label": "delta_c"}, {"type": "number", "label": "delta_p"}, {"type": "number", "label": "theta_1percent"}, {"type": "number", "label": "theta_all"}, {"type": "number", "label": "theta_c"}, {"type": "number", "label": "theta_p"}, {"type": "number", "label": "unreal_pl"}, {"type": "string", "label": "last_updated"}, {"type": "string", "label": "status"}]}');
  55. $('#temp').text(jdata);
  56. var d = new google.visualization.DataTable(jdata);
  57. portTbl.draw(d, options3);
  58. }
  59. });
  60. })
  61. // });
  62. </script>
  63. </head>
  64. <body>
  65. <div id="barchart_material" style="width: 900px; height: 500px;"></div>
  66. <div id='chartTbl_div' style='width: 900px; height: 500px;'></div>
  67. <div id="portTbl">
  68. <input type="button" id="b_reload" value="Reload" />
  69. </div>
  70. <div id='portTblDiv' style='width: 900px; height: 500px;'></div>
  71. <div id='temp'></div>
  72. </body>
  73. </html>