mirror of
https://github.com/OpenBB-finance/OpenBB.git
synced 2026-11-05 08:51:20 +00:00
1 line
10 KiB
JavaScript
1 line
10 KiB
JavaScript
"use strict";(self.webpackChunkdocs=self.webpackChunkdocs||[]).push([[89243],{3905:(e,t,n)=>{n.d(t,{Zo:()=>p,kt:()=>d});var a=n(67294);function i(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function r(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);t&&(a=a.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,a)}return n}function o(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?r(Object(n),!0).forEach((function(t){i(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):r(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}function s(e,t){if(null==e)return{};var n,a,i=function(e,t){if(null==e)return{};var n,a,i={},r=Object.keys(e);for(a=0;a<r.length;a++)n=r[a],t.indexOf(n)>=0||(i[n]=e[n]);return i}(e,t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);for(a=0;a<r.length;a++)n=r[a],t.indexOf(n)>=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(i[n]=e[n])}return i}var l=a.createContext({}),c=function(e){var t=a.useContext(l),n=t;return e&&(n="function"==typeof e?e(t):o(o({},t),e)),n},p=function(e){var t=c(e.components);return a.createElement(l.Provider,{value:t},e.children)},u={inlineCode:"code",wrapper:function(e){var t=e.children;return a.createElement(a.Fragment,{},t)}},m=a.forwardRef((function(e,t){var n=e.components,i=e.mdxType,r=e.originalType,l=e.parentName,p=s(e,["components","mdxType","originalType","parentName"]),m=c(n),d=i,h=m["".concat(l,".").concat(d)]||m[d]||u[d]||r;return n?a.createElement(h,o(o({ref:t},p),{},{components:n})):a.createElement(h,o({ref:t},p))}));function d(e,t){var n=arguments,i=t&&t.mdxType;if("string"==typeof e||i){var r=n.length,o=new Array(r);o[0]=m;var s={};for(var l in t)hasOwnProperty.call(t,l)&&(s[l]=t[l]);s.originalType=e,s.mdxType="string"==typeof e?e:i,o[1]=s;for(var c=2;c<r;c++)o[c]=n[c];return a.createElement.apply(null,o)}return a.createElement.apply(null,n)}m.displayName="MDXCreateElement"},62778:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>l,contentTitle:()=>o,default:()=>u,frontMatter:()=>r,metadata:()=>s,toc:()=>c});var a=n(87462),i=(n(67294),n(3905));const r={sidebar_position:5,title:"Scripts & Routines"},o=void 0,s={unversionedId:"guides/advanced/scripts-and-routines",id:"guides/advanced/scripts-and-routines",title:"Scripts & Routines",description:"The .openbb scripts offer the ability to automatically run a set of commands in the form of a routine. Furthermore, the scripts can be adapted, and documented, at any moment giving the user full control over the type of analysis you wish to do (and repeat). This can fundamental research, understanding market movements, finding hidden gems and even doing advanced statistical/econometric research.",source:"@site/content/terminal/guides/advanced/scripts-and-routines.md",sourceDirName:"guides/advanced",slug:"/guides/advanced/scripts-and-routines",permalink:"/terminal/guides/advanced/scripts-and-routines",draft:!1,editUrl:"https://github.com/OpenBB-finance/OpenBBTerminal/edit/main/website/content/terminal/guides/advanced/scripts-and-routines.md",tags:[],version:"current",sidebarPosition:5,frontMatter:{sidebar_position:5,title:"Scripts & Routines"},sidebar:"tutorialSidebar",previous:{title:"Customizing the Terminal",permalink:"/terminal/guides/advanced/customizing-the-terminal"},next:{title:"OpenBB Terminal Features",permalink:"/terminal/reference/"}},l={},c=[{value:"Explanation of scripts",id:"explanation-of-scripts",level:3},{value:"Executing a script",id:"executing-a-script",level:3},{value:"Custom arguments",id:"custom-arguments",level:4},{value:"Create your own script",id:"create-your-own-script",level:3}],p={toc:c};function u(e){let{components:t,...n}=e;return(0,i.kt)("wrapper",(0,a.Z)({},p,n,{components:t,mdxType:"MDXLayout"}),(0,i.kt)("p",null,"The ",(0,i.kt)("inlineCode",{parentName:"p"},".openbb")," scripts offer the ability to automatically run a set of commands in the form of a ",(0,i.kt)("strong",{parentName:"p"},"routine"),". Furthermore, the scripts can be adapted, and documented, at any moment giving the user full control over the type of analysis you wish to do (and repeat). This can fundamental research, understanding market movements, finding hidden gems and even doing advanced statistical/econometric research."),(0,i.kt)("h3",{id:"explanation-of-scripts"},"Explanation of scripts"),(0,i.kt)("p",null,"The script file below is titled ",(0,i.kt)("em",{parentName:"p"},"stocks_demo.openbb"),". This file follows the following logic:"),(0,i.kt)("ul",null,(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("b",null,"Comments"),": any text after a `#` is referred to as a comment. This is used to explain what is happening within the script and is not taking into account when running terminal commands."),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("b",null,"Commands"),": any text **without** a `#` is being ran inside the OpenBB Terminal. E.g. on the second line it says `stocks` thus within the OpenBB Terminal the script will enter `stocks` and run this for you.")),(0,i.kt)("p",null,"These scripts have a 1-to-1 relationship with how you would normally use the terminal. To get a better understanding of how the terminal is used, please see ",(0,i.kt)("a",{href:"https://docs.openbb.co/terminal/guides/basics",target:"_blank",rel:"noreferrer noopener"},"Structure of the OpenBB Terminal"),"."),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},"# Go into the stocks context\nstocks\n\n# Load a company ticker, e.g. Amazon\nload AMZN\n\n# Show a simple plot of the ticker, adding in any basic indicator.\ncandle --ma 20,30\n\n# Switch over to the due diligence menu\ndd\n\n# Show the price targets of Amazon, both the graph as well as the table\npt\npt --raw\n\n# Show estimates of annual and quarterly earnings as well as quarterly revenue estimates\nest\n\n# Open the comparison analysis menu (ca)\n../ca\n\n# Pick stocks that are competitors to Amazon\nadd ebay,wmt,tgt,baba,jd\n\n# Determine the valuations of each company\nvaluation\n\n# Show correlations between each company\nhcorr\n\n# Figure out the sentiment perceived of each company\nsentiment\n\n# Return to home\n/\n")),(0,i.kt)("h3",{id:"executing-a-script"},"Executing a script"),(0,i.kt)("p",null,"By going to the main menu as depicted below (accessible with ",(0,i.kt)("inlineCode",{parentName:"p"},"home"),"), the ",(0,i.kt)("inlineCode",{parentName:"p"},"exe")," command can be used. With this command you can run any ",(0,i.kt)("inlineCode",{parentName:"p"},".openbb")," script. These scripts are located where the application is located inside the routines folder."),(0,i.kt)("p",null,(0,i.kt)("img",{parentName:"p",src:"https://user-images.githubusercontent.com/46355364/174588513-5c52ea20-548a-4c2b-a4c1-6054e2d71786.png",alt:"Routine Exe OpenBB Terminal"})),(0,i.kt)("p",null,"Thus, using the earlier mentioned script, we can enter ",(0,i.kt)("inlineCode",{parentName:"p"},"exe stocks_demo.openbb")," which automatically runs all commands within the script file. Thus, it will return a candle chart with moving averages, price targets from Analysts, valuations of related companies, the correlation between these companies and the market sentiment. This results in the following:"),(0,i.kt)("p",null,(0,i.kt)("img",{parentName:"p",src:"https://user-images.githubusercontent.com/46355364/176903147-720eb2af-7e5d-40df-8ec6-7363cbc08430.png",alt:"Script Stocks Demo OpenBB"})),(0,i.kt)("h4",{id:"custom-arguments"},"Custom arguments"),(0,i.kt)("p",null,"Next to that, it is also possible to add in custom arguments to your script making the script more interactive and allow you to do the same analysis for multiple companies. This is done in the following script:"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},"# This script requires you to use arguments. This can be done with the following:\n# exe example_with_inputs.openbb -i TSLA,AAPL,MSFT\n\n# Go to the stocks menu\nstocks\n\n# Load a ticker, given the argument used. E.g. -i TSLA\nload $ARGV[0]\n\n# Enter the Technical Analysis (ta) menu\nta\n\n# Show the fibonacci retracement levels\nfib\n\n# Enter the comparison analysis (ca) menu\n../ca\n\n# Set two extra tickers based on the arguments used. E.g. -i TSLA,AAPL,MSFT\nset $ARGV[1],$ARGV[2]\n\n# Plot the historical prices\nhistorical\n\n# Return to home\n/\n")),(0,i.kt)("p",null,"This script includes ",(0,i.kt)("inlineCode",{parentName:"p"},"$ARGV[0]"),", ",(0,i.kt)("inlineCode",{parentName:"p"},"$ARGV[1]")," and ",(0,i.kt)("inlineCode",{parentName:"p"},"$ARGV[2]"),". This means that the script requires you to submit three arguments. In this case, they refer to ",(0,i.kt)("a",{href:"https://www.investopedia.com/ask/answers/12/what-is-a-stock-ticker.asp",target:"_blank",rel:"noreferrer noopener"},"stock tickers"),". Therefore, like the script also says, you can include these arguments with ",(0,i.kt)("inlineCode",{parentName:"p"},"-i")," followed by three tickers (e.g. ",(0,i.kt)("inlineCode",{parentName:"p"},"exe example_with_inputs.openbb -i TSLA,AAPL,MSFT"),"). This results in the following:"),(0,i.kt)("p",null,(0,i.kt)("img",{parentName:"p",src:"https://user-images.githubusercontent.com/46355364/176903205-3cb55bf5-8710-4ad6-8eef-f9a99294ea3b.png",alt:"Example with Inputs OpenBB Script"})),(0,i.kt)("p",null,"It is an incredibly simple script, but it gives an understanding what the possibilities are."),(0,i.kt)("h3",{id:"create-your-own-script"},"Create your own script"),(0,i.kt)("p",null,"Scripts and routines reside in the ",(0,i.kt)("inlineCode",{parentName:"p"},"routines")," folder and are automatically shown when you type ",(0,i.kt)("inlineCode",{parentName:"p"},"exe")," from the home screen (",(0,i.kt)("inlineCode",{parentName:"p"},"home"),"). To create your own, you can use the ",(0,i.kt)("inlineCode",{parentName:"p"},"template.openbb")," file as a basis but you are free to duplicate one of the demo files."),(0,i.kt)("p",null,"Within this template, some examples are given, and you are free to change the contents and rename the file. As long as the file remains in the same folder, you will be able to find your file automatically as shown below:"),(0,i.kt)("p",null,(0,i.kt)("img",{parentName:"p",src:"https://user-images.githubusercontent.com/46355364/176903253-00a5b0f9-a6e7-49c7-a1d8-49ae819e28e3.png",alt:"Show Copy of Template OpenBB Script"})))}u.isMDXComponent=!0}}]); |