Skip to content

Commit

Permalink
SageMaker Studio support
Browse files Browse the repository at this point in the history
  • Loading branch information
Oliver Steffmann committed Aug 14, 2022
1 parent 4e90986 commit fe131be
Show file tree
Hide file tree
Showing 21 changed files with 1,616 additions and 2 deletions.
144 changes: 144 additions & 0 deletions 5_SageMakerStudio/1_Setup.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Setup"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"scrolled": true
},
"outputs": [],
"source": [
"!./init_s3_bucket.sh"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"!./init_schema.sh"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"!pip install sagemaker-studio-image-build"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"scrolled": true
},
"outputs": [],
"source": [
"!sm-docker build docker/. --repository algotrading:1.0"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Attach Container as SageMaker Kernel"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import sagemaker as sage\n",
"from sagemaker import get_execution_role\n",
"\n",
"role = get_execution_role()\n",
"sess = sage.Session()\n",
"\n",
"account = sess.boto_session.client('sts').get_caller_identity()['Account']\n",
"region = sess.boto_session.region_name"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"!aws --region {region} sagemaker delete-image-version --image-name algotrading --version-number=1\n",
"!aws --region {region} sagemaker list-image-versions --image-name algotrading\n",
"!aws --region {region} sagemaker delete-image --image-name algotrading\n",
"!aws --region {region} sagemaker list-images\n",
"!aws --region {region} sagemaker delete-app-image-config --app-image-config-name=algotrading-config\n",
"!aws --region {region} sagemaker list-app-image-configs"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"!aws --region {region} sagemaker create-image --image-name algotrading --role-arn {role}\n",
"!aws --region {region} sagemaker list-images\n",
"!aws --region {region} sagemaker create-image-version --image-name algotrading --base-image \"{account}.dkr.ecr.{region}.amazonaws.com/algotrading:1.0\"\n",
"!aws --region {region} sagemaker list-image-versions --image-name algotrading\n",
"!aws --region {region} sagemaker create-app-image-config --cli-input-json file://app-image-config-input.json\n",
"!aws --region {region} sagemaker list-app-image-configs"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"domainid=!(aws --region {region} sagemaker list-domains --query 'Domains[0].DomainId' --output text)\n",
"domainid=domainid[0]\n",
"domainid"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"!aws --region {region} sagemaker update-domain --domain-id {domainid} --cli-input-json file://default-user-settings.json"
]
}
],
"metadata": {
"instance_type": "ml.t3.medium",
"kernelspec": {
"display_name": "Python 3 (Data Science)",
"language": "python",
"name": "python3__SAGEMAKER_INTERNAL__arn:aws:sagemaker:us-east-1:081325390199:image/datascience-1.0"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.10"
}
},
"nbformat": 4,
"nbformat_minor": 4
}
108 changes: 108 additions & 0 deletions 5_SageMakerStudio/2_Load_Data.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Load Daily Data into S3 Bucket\n",
"\n",
"### Obtaining Data\n",
"\n",
"\n",
"We use the dataset generated by [Chi Zhang](https://github.com/vermouth1992/drl-portfolio-management/tree/master/src/utils/datasets). It contains the historic price of 16 target stocks from NASDAQ100, including open, close, high and low prices from 2012-08-13 to 2017-08-11. Specifically, those stocks are: “AAPL”, “ATVI”, “CMCSA”, “COST”, “CSX”, “DISH”, “EA”, “EBAY”, “FB”, “GOOGL”, “HAS”, “ILMN”, “INTC”, “MAR”, “REGN” and “SBUX”.\n",
"\n",
"**This dataset is licensed under a MIT License**\n",
"\n",
"Copyright (c) 2017 Chi Zhang\n",
"\n",
"Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:\n",
"\n",
"The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\n",
"\n",
"THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n",
"\n",
"### Output dataset \n",
"\n",
"- Contains 5 years of EOD data for one of the stocks\n",
"- The data is saved into the specified S3 bucket as CSV.\n",
"\n",
"```\n",
"hist_data_daily/{sym}.csv (columns: dt,sym,open,high,low,close,vol)\n",
"```"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"S3_BUCKET=!(aws cloudformation list-exports --query \"Exports[?Name=='algotrading-s3bucket'].Value\" --output text)\n",
"S3_BUCKET=S3_BUCKET[0]\n",
"S3_BUCKET"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# symbol\n",
"sym='INTC'"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"%run data_prep.py {sym}"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import pandas as pd\n",
"\n",
"df = pd.read_csv(\"INTC.csv\",infer_datetime_format=True, parse_dates=['dt'], index_col=['dt'])\n",
"df.head()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"!aws s3 cp {sym}.csv s3://{S3_BUCKET}/hist_data_daily/"
]
}
],
"metadata": {
"instance_type": "ml.t3.medium",
"kernelspec": {
"display_name": "Python 3 (Data Science)",
"language": "python",
"name": "python3__SAGEMAKER_INTERNAL__arn:aws:sagemaker:us-east-1:081325390199:image/datascience-1.0"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.10"
}
},
"nbformat": 4,
"nbformat_minor": 4
}
Loading

0 comments on commit fe131be

Please sign in to comment.