{"cells": [{"metadata": {"trusted": true}, "cell_type": "code", "source": "// \u5bfc\u5165\u9700\u8981\u7684\u7a0b\u5e8f\u5305, \u5728\u53d1\u660e\u8005 \"\u7b56\u7565\u7f16\u8f91\u9875\u9762\" \u70b9\u51fb \"\u4fdd\u5b58\u56de\u6d4b\u8bbe\u7f6e\" \u5373\u53ef\u83b7\u53d6\u5b57\u7b26\u4e32\u914d\u7f6e, \u8f6c\u6362\u4e3a\u5bf9\u8c61\u5373\u53ef\nvar fmz = require(\"fmz\")                           // \u5f15\u5165\u540e\u81ea\u52a8\u5bfc\u5165 talib, TA, plot \u5e93\nvar task = fmz.VCtx({\nstart: '2019-09-19 00:00:00',\nend: '2019-09-28 12:00:00',\nperiod: '15m',\nexchanges: [{\"eid\":\"Futures_OKCoin\",\"currency\":\"BTC_USD\",\"stocks\":1},{\"eid\":\"OKEX\",\"currency\":\"BTC_USDT\",\"balance\":10000,\"stocks\":0}]\n})", "execution_count": 1, "outputs": []}, {"metadata": {"trusted": true}, "cell_type": "code", "source": "exchanges[0].SetContractType(\"quarter\")  // \u7b2c\u4e00\u4e2a\u4ea4\u6613\u6240\u5bf9\u8c61OKEX\u671f\u8d27\uff08eid:Futures_OKCoin\uff09\u8c03\u7528\u8bbe\u7f6e\u5f53\u524d\u5408\u7ea6\u7684\u51fd\u6570\uff0c\u8bbe\u7f6e\u4e3a\u5b63\u5ea6\u5408\u7ea6\nvar initQuarterAcc = exchanges[0].GetAccount()  // OKEX\u671f\u8d27\u4ea4\u6613\u6240\u521d\u59cb\u65f6\u7684\u8d26\u6237\u4fe1\u606f\uff0c\u8bb0\u5f55\u5728\u53d8\u91cfinitQuarterAcc\ninitQuarterAcc", "execution_count": 2, "outputs": [{"output_type": "execute_result", "execution_count": 2, "data": {"text/plain": "{ Balance: 0, FrozenBalance: 0, Stocks: 1, FrozenStocks: 0 }"}, "metadata": {}}]}, {"metadata": {"trusted": true}, "cell_type": "code", "source": "var initSpotAcc = exchanges[1].GetAccount()     // OKEX\u73b0\u8d27\u4ea4\u6613\u6240\u521d\u59cb\u65f6\u7684\u8d26\u6237\u4fe1\u606f\uff0c\u8bb0\u5f55\u5728\u53d8\u91cfinitSpotAcc\ninitSpotAcc", "execution_count": 3, "outputs": [{"output_type": "execute_result", "execution_count": 3, "data": {"text/plain": "{ Balance: 10000, FrozenBalance: 0, Stocks: 0, FrozenStocks: 0 }"}, "metadata": {}}]}, {"metadata": {"trusted": true}, "cell_type": "code", "source": "var quarterTicker1 = exchanges[0].GetTicker()   // \u83b7\u53d6\u671f\u8d27\u4ea4\u6613\u6240\u884c\u60c5\uff0c\u8bb0\u5f55\u5728\u53d8\u91cfquarterTicker1\nquarterTicker1", "execution_count": 4, "outputs": [{"output_type": "execute_result", "execution_count": 4, "data": {"text/plain": "{ Time: 1568851210000,\n  High: 10441.25002,\n  Low: 10441.25,\n  Sell: 10441.25002,\n  Buy: 10441.25,\n  Last: 10441.25001,\n  Volume: 1772,\n  OpenInterest: 0 }"}, "metadata": {}}]}, {"metadata": {"trusted": true}, "cell_type": "code", "source": "var spotTicker1 = exchanges[1].GetTicker()     // \u83b7\u53d6\u73b0\u8d27\u4ea4\u6613\u6240\u884c\u60c5\uff0c\u8bb0\u5f55\u5728\u53d8\u91cfspotTicker1\nspotTicker1", "execution_count": 5, "outputs": [{"output_type": "execute_result", "execution_count": 5, "data": {"text/plain": "{ Time: 1568851210000,\n  High: 10156.60000002,\n  Low: 10156.6,\n  Sell: 10156.60000002,\n  Buy: 10156.6,\n  Last: 10156.60000001,\n  Volume: 7.4443,\n  OpenInterest: 0 }"}, "metadata": {}}]}, {"metadata": {"trusted": true}, "cell_type": "code", "source": "quarterTicker1.Buy - spotTicker1.Sell         // \u671f\u8d27\u505a\u7a7a\uff0c\u73b0\u8d27\u505a\u591a\u7684\u5dee\u4ef7", "execution_count": 6, "outputs": [{"output_type": "execute_result", "execution_count": 6, "data": {"text/plain": "284.64999997999985"}, "metadata": {}}]}, {"metadata": {"trusted": true}, "cell_type": "code", "source": "exchanges[0].SetDirection(\"sell\")             // \u8bbe\u7f6e\u671f\u8d27\u4ea4\u6613\u6240\uff0c\u4ea4\u6613\u65b9\u5411\u4e3a\u505a\u7a7a\nvar quarterId1 = exchanges[0].Sell(quarterTicker1.Buy, 10)  // \u671f\u8d27\u505a\u7a7a\u4e0b\u5355\uff0c\u4e0b\u5355\u91cf\u4e3a10\u5f20\u5408\u7ea6\uff0c\u8fd4\u56de\u7684\u8ba2\u5355ID\u8bb0\u5f55\u5728\u53d8\u91cfquarterId1\nexchanges[0].GetOrder(quarterId1)                           // \u67e5\u8be2\u671f\u8d27\u8ba2\u5355ID\u4e3aquarterId1\u7684\u8ba2\u5355\u8be6\u60c5", "execution_count": 7, "outputs": [{"output_type": "execute_result", "execution_count": 7, "data": {"text/plain": "{ Id: 1,\n  Price: 10441.25,\n  Amount: 10,\n  DealAmount: 10,\n  AvgPrice: 10441.25,\n  Type: 1,\n  Offset: 0,\n  Status: 1,\n  ContractType: 'quarter' }"}, "metadata": {}}]}, {"metadata": {"trusted": true}, "cell_type": "code", "source": "var spotAmount = 10 * 100 / quarterTicker1.Buy                  // \u8ba1\u7b9710\u5f20\u5408\u7ea6\u7b49\u503c\u7684\u5e01\u6570\uff0c\u4f5c\u4e3a\u73b0\u8d27\u7684\u4e0b\u5355\u91cf\nvar spotId1 = exchanges[1].Buy(spotTicker1.Sell, spotAmount)    // \u73b0\u8d27\u4ea4\u6613\u6240\u4e0b\u5355\nexchanges[1].GetOrder(spotId1)                                  // \u67e5\u8be2\u73b0\u8d27\u8ba2\u5355ID\u4e3aspotId1\u7684\u8ba2\u5355\u8be6\u60c5", "execution_count": 8, "outputs": [{"output_type": "execute_result", "execution_count": 8, "data": {"text/plain": "{ Id: 1,\n  Price: 10156.60000002,\n  Amount: 0.0957,\n  DealAmount: 0.0957,\n  AvgPrice: 10156.60000002,\n  Type: 0,\n  Offset: 0,\n  Status: 1,\n  ContractType: 'BTC_USDT_OKEX' }"}, "metadata": {}}]}, {"metadata": {}, "cell_type": "markdown", "source": "\u53ef\u4ee5\u770b\u5230\u8ba2\u5355quarterId1\u3001spotId1\u8ba2\u5355\u90fd\u5b8c\u5168\u6210\u4ea4\uff0c\u5373\u5bf9\u51b2\u5f00\u4ed3\u5b8c\u6210\u3002"}, {"metadata": {"trusted": true}, "cell_type": "code", "source": "Sleep(1000 * 60 * 60 * 24 * 7)            // \u6301\u4ed3\u4e00\u6bb5\u65f6\u95f4\uff0c\u7b49\u5f85\u5dee\u4ef7\u53d8\u5c0f\u5e73\u4ed3\u3002", "execution_count": 9, "outputs": []}, {"metadata": {}, "cell_type": "markdown", "source": "\u7b49\u5f85\u65f6\u95f4\u8fc7\u540e\uff0c\u51c6\u5907\u5e73\u4ed3\u3002\u83b7\u53d6\u5f53\u524d\u7684\u884c\u60c5```quarterTicker2```\u3001```spotTicker2```\u5e76\u4e14\u6253\u5370\u3002\n\u671f\u8d27\u4ea4\u6613\u6240\u5bf9\u8c61\u7684\u4ea4\u6613\u65b9\u5411\u8bbe\u7f6e\u4e3a\u5e73\u7a7a\u4ed3\uff1a```exchanges[0].SetDirection(\"closesell\")```\u4e0b\u5355\u5e73\u4ed3\u3002\n\u6253\u5370\u5e73\u4ed3\u8ba2\u5355\u7684\u8be6\u60c5\uff0c\u663e\u793a\u5e73\u4ed3\u8ba2\u5355\u5b8c\u5168\u6210\u4ea4\uff0c\u5e73\u4ed3\u5b8c\u6210\u3002"}, {"metadata": {"trusted": true}, "cell_type": "code", "source": "var quarterTicker2 = exchanges[0].GetTicker()    // \u83b7\u53d6\u5f53\u524d\u671f\u8d27\u4ea4\u6613\u6240\u7684\u884c\u60c5\uff0c\u8bb0\u5f55\u5728\u53d8\u91cfquarterTicker2\nquarterTicker2", "execution_count": 10, "outputs": [{"output_type": "execute_result", "execution_count": 10, "data": {"text/plain": "{ Time: 1569456010000,\n  High: 8497.20002,\n  Low: 8497.2,\n  Sell: 8497.20002,\n  Buy: 8497.2,\n  Last: 8497.20001,\n  Volume: 4311,\n  OpenInterest: 0 }"}, "metadata": {}}]}, {"metadata": {"trusted": true}, "cell_type": "code", "source": "var spotTicker2 = exchanges[1].GetTicker()       // \u83b7\u53d6\u5f53\u524d\u73b0\u8d27\u4ea4\u6613\u6240\u7684\u884c\u60c5\uff0c\u8bb0\u5f55\u5728\u53d8\u91cfspotTicker2\nspotTicker2", "execution_count": 11, "outputs": [{"output_type": "execute_result", "execution_count": 11, "data": {"text/plain": "{ Time: 1569456114600,\n  High: 8444.70000001,\n  Low: 8444.69999999,\n  Sell: 8444.70000001,\n  Buy: 8444.69999999,\n  Last: 8444.7,\n  Volume: 78.6273,\n  OpenInterest: 0 }"}, "metadata": {}}]}, {"metadata": {"trusted": true}, "cell_type": "code", "source": "quarterTicker2.Sell - spotTicker2.Buy            // \u671f\u8d27\u7a7a\u5934\u4ed3\u4f4d\u5e73\u4ed3\uff0c\u73b0\u8d27\u591a\u5934\u4ed3\u4f4d\u5e73\u4ed3\u7684\u5dee\u4ef7", "execution_count": 12, "outputs": [{"output_type": "execute_result", "execution_count": 12, "data": {"text/plain": "52.5000200100003"}, "metadata": {}}]}, {"metadata": {"trusted": true}, "cell_type": "code", "source": "exchanges[0].SetDirection(\"closesell\")           // \u8bbe\u7f6e\u671f\u8d27\u4ea4\u6613\u6240\u5f53\u524d\u4ea4\u6613\u65b9\u5411\u4e3a\u5e73\u7a7a\u4ed3\nvar quarterId2 = exchanges[0].Buy(quarterTicker2.Sell, 10)       // \u671f\u8d27\u4ea4\u6613\u6240\u4e0b\u5355\u5e73\u4ed3\uff0c\u5e76\u4e14\u8bb0\u5f55\u4e0b\u5355ID\uff0c\u8bb0\u5f55\u5230\u53d8\u91cfquarterId2\nexchanges[0].GetOrder(quarterId2)                                // \u67e5\u8be2\u671f\u8d27\u5e73\u4ed3\u8ba2\u5355\u8be6\u60c5", "execution_count": 13, "outputs": [{"output_type": "execute_result", "execution_count": 13, "data": {"text/plain": "{ Id: 2,\n  Price: 8497.20002,\n  Amount: 10,\n  DealAmount: 10,\n  AvgPrice: 8493.95335,\n  Type: 0,\n  Offset: 1,\n  Status: 1,\n  ContractType: 'quarter' }"}, "metadata": {}}]}, {"metadata": {"trusted": true}, "cell_type": "code", "source": "var spotId2 = exchanges[1].Sell(spotTicker2.Buy, spotAmount)     // \u73b0\u8d27\u4ea4\u6613\u6240\u4e0b\u5355\u5e73\u4ed3\uff0c\u5e76\u4e14\u8bb0\u5f55\u4e0b\u5355ID\uff0c\u8bb0\u5f55\u5230\u53d8\u91cfspotId2\nexchanges[1].GetOrder(spotId2)                                   // \u67e5\u8be2\u73b0\u8d27\u5e73\u4ed3\u8ba2\u5355\u8be6\u60c5", "execution_count": 14, "outputs": [{"output_type": "execute_result", "execution_count": 14, "data": {"text/plain": "{ Id: 2,\n  Price: 8444.69999999,\n  Amount: 0.0957,\n  DealAmount: 0.0957,\n  AvgPrice: 8444.69999999,\n  Type: 1,\n  Offset: 0,\n  Status: 1,\n  ContractType: 'BTC_USDT_OKEX' }"}, "metadata": {}}]}, {"metadata": {"trusted": true}, "cell_type": "code", "source": "var nowQuarterAcc = exchanges[0].GetAccount()     // \u83b7\u53d6\u5f53\u524d\u671f\u8d27\u4ea4\u6613\u6240\u8d26\u6237\u4fe1\u606f\uff0c\u8bb0\u5f55\u5728\u53d8\u91cfnowQuarterAcc\nnowQuarterAcc                                     ", "execution_count": 15, "outputs": [{"output_type": "execute_result", "execution_count": 15, "data": {"text/plain": "{ Balance: 0,\n  FrozenBalance: 0,\n  Stocks: 1.021786026184,\n  FrozenStocks: 0 }"}, "metadata": {}}]}, {"metadata": {"trusted": true}, "cell_type": "code", "source": "var nowSpotAcc = exchanges[1].GetAccount()        // \u83b7\u53d6\u5f53\u524d\u73b0\u8d27\u4ea4\u6613\u6240\u8d26\u6237\u4fe1\u606f\uff0c\u8bb0\u5f55\u5728\u53d8\u91cfnowSpotAcc\nnowSpotAcc", "execution_count": 16, "outputs": [{"output_type": "execute_result", "execution_count": 16, "data": {"text/plain": "{ Balance: 9834.74705446,\n  FrozenBalance: 0,\n  Stocks: 0,\n  FrozenStocks: 0 }"}, "metadata": {}}]}, {"metadata": {}, "cell_type": "markdown", "source": "\u901a\u8fc7\u5bf9\u6bd4\u6700\u521d\u8d26\u6237\u548c\u5f53\u524d\u8d26\u6237\uff0c\u8ba1\u7b97\u51fa\u6b64\u6b21\u5bf9\u51b2\u64cd\u4f5c\u7684\u6536\u76ca\u76c8\u4e8f\u3002"}, {"metadata": {"trusted": true}, "cell_type": "code", "source": "var diffStocks = Math.abs(nowQuarterAcc.Stocks - initQuarterAcc.Stocks)\nvar diffBalance = nowSpotAcc.Balance - initSpotAcc.Balance\nif (nowQuarterAcc.Stocks - initQuarterAcc.Stocks > 0) {\n    console.log(\"\u6536\u76ca\uff1a\", diffStocks * spotTicker2.Buy + diffBalance)\n} else {\n    console.log(\"\u6536\u76ca\uff1a\", diffBalance - diffStocks * spotTicker2.Buy)\n}", "execution_count": 17, "outputs": [{"output_type": "stream", "text": "\u6536\u76ca\uff1a 18.72350977580652\n", "name": "stdout"}]}, {"metadata": {}, "cell_type": "markdown", "source": "\u4e0b\u9762\u6211\u4eec\u770b\u4e0b\u4e3a\u4ec0\u4e48\u6b64\u6b21\u5bf9\u51b2\u662f\u76c8\u5229\u7684\u3002\u6211\u4eec\u53ef\u4ee5\u770b\u5230\u753b\u51fa\u7684\u56fe\u8868\uff0c\u671f\u8d27\u4ef7\u683c\u662f\u84dd\u8272\u7684\u7ebf\uff0c\u73b0\u8d27\u4ef7\u683c\u662f\u6a59\u8272\u7684\u7ebf\uff0c\u4e24\u4e2a\u4ef7\u683c\u90fd\u662f\u4e0b\u964d\u7684\uff0c\u671f\u8d27\u4ef7\u683c\u4e0b\u964d\u7684\u6bd4\u73b0\u8d27\u4ef7\u683c\u5feb\u3002"}, {"metadata": {"trusted": true}, "cell_type": "code", "source": "var objQuarter = {\n    \"index\" : [1, 2],                                          // \u7d22\u5f15index \u4e3a1 \u5373\u7b2c\u4e00\u4e2a\u65f6\u523b\uff0c\u5f00\u4ed3\u65f6\u523b\uff0c2\u4e3a\u5e73\u4ed3\u65f6\u523b\u3002\n    \"arrPrice\" : [quarterTicker1.Buy, quarterTicker2.Sell],\n}\nvar objSpot = {\n    \"index\" : [1, 2],\n    \"arrPrice\" : [spotTicker1.Sell, spotTicker2.Buy],\n}\nplot([{name: 'quarter', x: objQuarter.index, y: objQuarter.arrPrice}, {name: 'spot', x: objSpot.index, y: objSpot.arrPrice}])", "execution_count": 18, "outputs": [{"output_type": "execute_result", "execution_count": 18, "data": {"text/html": "<div class='plotly-plot'><div id='notebook-plot-1570698837341'></div><script>function plot(){Plotly.plot('notebook-plot-1570698837341',[{\"name\":\"quarter\",\"x\":[1,2],\"y\":[10441.25,8497.20002]},{\"name\":\"spot\",\"x\":[1,2],\"y\":[10156.60000002,8444.69999999]}],);}if(window.Plotly){plot();}else{var head = document.head || document.getElementsByTagName('head')[0];var s = document.createElement('script');s.charset='utf-8';s.src = 'https://www.fmz.com/pkg/plotly-latest.min.js';s.type = 'text/javascript';s.async = false;s.onreadystatechange = s.onload = plot;head.appendChild(s);}</script></div>"}, "metadata": {}}]}, {"metadata": {}, "cell_type": "markdown", "source": "\u6211\u4eec\u518d\u770b\u4e0b\u5dee\u4ef7\u7684\u53d8\u5316\u60c5\u51b5\uff0c\u5dee\u4ef7\u662f\u4ece\u5bf9\u51b2\u5f00\u4ed3\u65f6\u7684284\uff08\u5373\u671f\u8d27\u505a\u7a7a\uff0c\u73b0\u8d27\u6700\u591a\uff09\uff0c\u5230\u5e73\u4ed3\u65f6\u768452\uff08\u671f\u8d27\u7a7a\u5934\u6301\u4ed3\u5e73\u4ed3\uff0c\u73b0\u8d27\u591a\u4ed3\u5e73\u4ed3\uff09\u3002\u5dee\u4ef7\u662f\u4ece\u5927\u5230\u5c0f\u3002"}, {"metadata": {"trusted": true}, "cell_type": "code", "source": "var arrDiffPrice = [quarterTicker1.Buy - spotTicker1.Sell, quarterTicker2.Sell - spotTicker2.Buy]\nplot(arrDiffPrice)", "execution_count": 19, "outputs": [{"output_type": "execute_result", "execution_count": 19, "data": {"text/html": "<div class='plotly-plot'><div id='notebook-plot-1570698840954'></div><script>function plot(){Plotly.plot('notebook-plot-1570698840954',[{\"x\":[1,2],\"y\":[284.64999997999985,52.5000200100003]}],);}if(window.Plotly){plot();}else{var head = document.head || document.getElementsByTagName('head')[0];var s = document.createElement('script');s.charset='utf-8';s.src = 'https://www.fmz.com/pkg/plotly-latest.min.js';s.type = 'text/javascript';s.async = false;s.onreadystatechange = s.onload = plot;head.appendChild(s);}</script></div>"}, "metadata": {}}]}, {"metadata": {}, "cell_type": "markdown", "source": "### \u6211\u4eec\u4e3e\u4e2a\u4f8b\u5b50\uff0ca1\u4e3a\u65f6\u523b1\u7684\u671f\u8d27\u4ef7\u683c\uff0cb1\u4e3a\u65f6\u523b1\u7684\u73b0\u8d27\u4ef7\u683c\u3002a2\u4e3a\u65f6\u523b2\u7684\u671f\u8d27\u4ef7\u683c\uff0cb2\u4e3a\u65f6\u523b2\u7684\u73b0\u8d27\u4ef7\u683c\u3002\n\n\u53ea\u8981a1-b1\u5373\u65f6\u523b1\u7684\u671f\u8d27\u73b0\u8d27\u5dee\u4ef7\u5927\u4e8ea2-b2\u5373\u65f6\u523b2\u65f6\u7684\u671f\u8d27\u73b0\u8d27\u5dee\u4ef7\uff0c\u5c31\u53ef\u4ee5\u63a8\u51faa1 - a2 > b1 - b2\u3002\n\u6709\u4e09\u79cd\u60c5\u51b5\uff1a\uff08\u671f\u8d27\u73b0\u8d27\u6301\u4ed3\u5934\u5bf8\u89c4\u6a21\u76f8\u540c\uff09\n\n- 1\u3001a1 - a2\u5927\u4e8e0\uff0cb1 - b2\u5927\u4e8e0\n  a1 - a2\u4e3a\u671f\u8d27\u76c8\u5229\u7684\u5dee\u4ef7\uff0cb1 - b2\u4e3a\u73b0\u8d27\u4e8f\u635f\u7684\u5dee\u4ef7\uff08\u56e0\u4e3a\u73b0\u8d27\u505a\u591a\uff0c\u5f00\u59cb\u4e70\u5165\u7684\u4ef7\u683c\u6bd4\u5356\u51fa\u5e73\u4ed3\u7684\u4ef7\u683c\u9ad8\uff0c\u6240\u4ee5\u4e8f\u94b1\uff09\uff0c\u4f46\u662f\u671f\u8d27\u76c8\u5229\u7684\u5927\u4e8e\u73b0\u8d27\u4e8f\u635f\u7684\u3002\u6240\u4ee5\u6574\u4f53\u662f\u76c8\u5229\u3002\u8fd9\u79cd\u60c5\u51b5\u5bf9\u5e94\u7684\u5c31\u662f\u6b65\u9aa4In[8]\u4e2d\u7684\u56fe\u8868\u60c5\u51b5\u3002\n  \n  \n- 2\u3001a1 - a2\u5927\u4e8e0\uff0cb1 - b2\u5c0f\u4e8e0\n  a1 - a2\u4e3a\u671f\u8d27\u76c8\u5229\u7684\u5dee\u4ef7\uff0cb1 - b2\u4e3a\u73b0\u8d27\u76c8\u5229\u7684\u5dee\u4ef7\uff08b1 - b2 \u5c0f\u4e8e0\uff0c\u8bf4\u660eb2\u5927\u4e8eb1\uff0c\u5373\u5f00\u4ed3\u4e70\u5165\u7684\u4ef7\u683c\u4f4e\uff0c\u5356\u51fa\u5e73\u4ed3\u7684\u4ef7\u683c\u9ad8\uff0c\u6240\u4ee5\u76c8\u5229\uff09\n  \n  \n- 3\u3001a1 - a2\u5c0f\u4e8e0\uff0cb1 - b2\u5c0f\u4e8e0\n  a1 - a2\u4e3a\u671f\u8d27\u4e8f\u635f\u7684\u5dee\u4ef7\uff0cb1 - b2\u4e3a\u73b0\u8d27\u76c8\u5229\u7684\u5dee\u4ef7\u7531\u4e8ea1 - a2 > b1 - b2\uff0ca1 - a2\u7684\u7edd\u5bf9\u503c\u5c0f\u4e8eb1 - b2\u7684\u7edd\u5bf9\u503c\uff0c\u73b0\u8d27\u7684\u76c8\u5229\u5927\u4e8e\u671f\u8d27\u7684\u4e8f\u635f\u3002\u6574\u4f53\u4e3a\u76c8\u5229\u3002\n\n\n\u4e0d\u5b58\u5728 a1 - a2\u5c0f\u4e8e0\uff0cb1 - b2\u5927\u4e8e0\u8fd9\u79cd\u60c5\u51b5\uff0c\u56e0\u4e3a\u5df2\u7ecf\u9650\u5b9a\u4e86a1 - a2 > b1 - b2\u3002\u540c\u6837\u5982\u679ca1 - a2\u7b49\u4e8e0\uff0c\u7531\u4e8ea1 - a2 > b1 - b2\u9650\u5b9a\uff0cb1 - b2\u5c31\u4e00\u5b9a\u662f\u5c0f\u4e8e0\u7684\u3002\u6240\u4ee5\u53ea\u8981\u662f\u671f\u8d27\u505a\u7a7a\uff0c\u73b0\u8d27\u505a\u591a\u7684\u5bf9\u51b2\u65b9\u5f0f\uff0c\u7b26\u5408\u6761\u4ef6a1 - b1 > a2 - b2\uff0c\u7684\u5f00\u4ed3\u5e73\u4ed3\u64cd\u4f5c\uff0c\u5373\u4e3a\u76c8\u5229\u5bf9\u51b2\u3002\n\n\u4f8b\u5982\u4ee5\u4e0b\u6a21\u578b\u4e3a\u5176\u4e2d\u4e00\u79cd\u60c5\u51b5\uff1a"}, {"metadata": {"trusted": true}, "cell_type": "code", "source": "var a1 = 10\nvar b1 = 5\nvar a2 = 11\nvar b2 = 9\n\n// a1 - b1 > a2 - b2 \u63a8\u51fa \uff1a a1 - a2 > b1 - b2\n\nvar objA = {\n    \"index\" : [1, 2],\n    \"arrPrice\" : [a1, a2],\n}\nvar objB = {\n    \"index\" : [1, 2],\n    \"arrPrice\" : [b1, b2],\n}\nplot([{name : \"a\", x : objA.index, y : objA.arrPrice}, {name : \"b\", x : objB.index, y : objB.arrPrice}])", "execution_count": 20, "outputs": [{"output_type": "execute_result", "execution_count": 20, "data": {"text/html": "<div class='plotly-plot'><div id='notebook-plot-1570698844523'></div><script>function plot(){Plotly.plot('notebook-plot-1570698844523',[{\"name\":\"a\",\"x\":[1,2],\"y\":[10,11]},{\"name\":\"b\",\"x\":[1,2],\"y\":[5,9]}],);}if(window.Plotly){plot();}else{var head = document.head || document.getElementsByTagName('head')[0];var s = document.createElement('script');s.charset='utf-8';s.src = 'https://www.fmz.com/pkg/plotly-latest.min.js';s.type = 'text/javascript';s.async = false;s.onreadystatechange = s.onload = plot;head.appendChild(s);}</script></div>"}, "metadata": {}}]}], "metadata": {"kernelspec": {"name": "javascript", "display_name": "Javascript (Node.js)", "language": "javascript"}, "language_info": {"name": "javascript", "version": "8.10.0", "mimetype": "application/javascript", "file_extension": ".js"}}, "nbformat": 4, "nbformat_minor": 2}